This is the new AWS CloudFormation Template Reference Guide. Please update your bookmarks and links. For help getting started with CloudFormation, see the AWS CloudFormation User Guide.
AWS::ApiGateway::GatewayResponse
The AWS::ApiGateway::GatewayResponse resource creates a gateway response for your API. When you delete a stack containing this resource, your custom gateway responses are reset. For more information, see API Gateway Responses in the API Gateway Developer Guide.
Syntax
To declare this entity in your AWS 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:ValueResponseType:Key:ValueStringRestApiId:StringStatusCode: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: Object of String Pattern: [a-zA-Z0-9]+Update requires: No interruption 
- ResponseTemplates
- 
                    Response templates of the GatewayResponse as a string-to-string map of key-value pairs. Required: No Type: Object of String Pattern: [a-zA-Z0-9]+Update requires: No interruption 
- ResponseType
- 
                    The response type of the associated GatewayResponse. Required: Yes Type: String Allowed values: DEFAULT_4XX | DEFAULT_5XX | RESOURCE_NOT_FOUND | UNAUTHORIZED | INVALID_API_KEY | ACCESS_DENIED | AUTHORIZER_FAILURE | AUTHORIZER_CONFIGURATION_ERROR | INVALID_SIGNATURE | EXPIRED_TOKEN | MISSING_AUTHENTICATION_TOKEN | INTEGRATION_FAILURE | INTEGRATION_TIMEOUT | API_CONFIGURATION_ERROR | UNSUPPORTED_MEDIA_TYPE | BAD_REQUEST_PARAMETERS | BAD_REQUEST_BODY | REQUEST_TOO_LARGE | THROTTLED | QUOTA_EXCEEDED | WAF_FILTEREDUpdate 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
The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.
- Id
- 
                            The ID for the gateway response. For example: abc123.
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