AWS::ApiGateway::GatewayResponse
The AWS::ApiGateway::GatewayResponse
resource creates a gateway response for your API. For more information, see API Gateway Responses in the API Gateway Developer Guide.
Syntax
To declare this entity in your Amazon CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::ApiGateway::GatewayResponse", "Properties" : { "ResponseParameters" :
{
, "ResponseTemplates" :Key
:Value
, ...}{
, "ResponseType" :Key
:Value
, ...}String
, "RestApiId" :String
, "StatusCode" :String
} }
YAML
Type: AWS::ApiGateway::GatewayResponse Properties: ResponseParameters:
ResponseTemplates:
Key
:Value
ResponseType:
Key
:Value
String
RestApiId:String
StatusCode:String
Properties
ResponseParameters
-
Response parameters (paths, query strings and headers) of the GatewayResponse as a string-to-string map of key-value pairs.
Required: No
Type: Map of String
Update requires: No interruption
ResponseTemplates
-
Response templates of the GatewayResponse as a string-to-string map of key-value pairs.
Required: No
Type: Map of String
Update requires: No interruption
ResponseType
-
The response type of the associated GatewayResponse.
Required: Yes
Type: String
Allowed values:
ACCESS_DENIED | API_CONFIGURATION_ERROR | AUTHORIZER_CONFIGURATION_ERROR | AUTHORIZER_FAILURE | BAD_REQUEST_BODY | BAD_REQUEST_PARAMETERS | DEFAULT_4XX | DEFAULT_5XX | EXPIRED_TOKEN | INTEGRATION_FAILURE | INTEGRATION_TIMEOUT | INVALID_API_KEY | INVALID_SIGNATURE | MISSING_AUTHENTICATION_TOKEN | QUOTA_EXCEEDED | REQUEST_TOO_LARGE | RESOURCE_NOT_FOUND | THROTTLED | UNAUTHORIZED | UNSUPPORTED_MEDIA_TYPE
Update requires: Replacement
RestApiId
-
The string identifier of the associated RestApi.
Required: Yes
Type: String
Update requires: Replacement
StatusCode
-
The HTTP status code for this GatewayResponse.
Required: No
Type: String
Update requires: No interruption
Return values
Fn::GetAtt
Examples
404 Response
The following example returns a 404 status code for resource not found instead of missing authentication token for a CORS request (applicable to unsecured/unrestricted APIs).
JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "RestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Name": "myRestApi" } }, "GatewayResponse": { "Type": "AWS::ApiGateway::GatewayResponse", "Properties": { "ResponseParameters": { "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Allow-Headers": "'*'" }, "ResponseType": "MISSING_AUTHENTICATION_TOKEN", "RestApiId": { "Ref": "RestApi" }, "StatusCode": "404" } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Resources: RestApi: Type: AWS::ApiGateway::RestApi Properties: Name: myRestApi GatewayResponse: Type: AWS::ApiGateway::GatewayResponse Properties: ResponseParameters: gatewayresponse.header.Access-Control-Allow-Origin: "'*'" gatewayresponse.header.Access-Control-Allow-Headers: "'*'" ResponseType: MISSING_AUTHENTICATION_TOKEN RestApiId: !Ref RestApi StatusCode: '404'
Parameterized Response
The following example creates a response for an API based on the supplied parameters.
JSON
{ "Parameters": { "apiName": { "Type": "String" }, "responseParameter1": { "Type": "String" }, "responseParameter2": { "Type": "String" }, "responseType": { "Type": "String" }, "statusCode": { "Type": "String" } }, "Resources": { "RestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Name": { "Ref": "apiName" } } }, "GatewayResponse": { "Type": "AWS::ApiGateway::GatewayResponse", "Properties": { "ResponseParameters": { "gatewayresponse.header.k1": { "Ref": "responseParameter1" }, "gatewayresponse.header.k2": { "Ref": "responseParameter2" } }, "ResponseType": { "Ref": "responseType" }, "RestApiId": { "Ref": "RestApi" }, "StatusCode": { "Ref": "statusCode" } } } } }
YAML
Parameters: apiName : Type : String responseParameter1: Type : String responseParameter2: Type : String responseType: Type : String statusCode: Type : String Resources : RestApi: Type: AWS::ApiGateway::RestApi Properties: Name: !Ref apiName GatewayResponse: Type: AWS::ApiGateway::GatewayResponse Properties: ResponseParameters: gatewayresponse.header.k1 : !Ref responseParameter1 gatewayresponse.header.k2 : !Ref responseParameter2 ResponseType: !Ref responseType RestApiId: !Ref RestApi StatusCode: !Ref statusCode
See also
-
gatewayresponse:put in the Amazon API Gateway REST API Reference