ResponseType Class
Supported types of gateway responses.
| Source | aws-apigateway/lib/gateway-response.ts |
|---|
Example
ts
const api = new apigateway.RestApi(this, 'books-api');
api.addGatewayResponse('test-response', {
type: apigateway.ResponseType.ACCESS_DENIED,
statusCode: '500',
responseHeaders: {
// Note that values must be enclosed within a pair of single quotes
'Access-Control-Allow-Origin': "'test.com'",
'test-key': "'test-value'",
},
templates: {
'application/json': '{ "message": $context.error.messageString, "statusCode": "488", "type": "$context.error.responseType" }'
}
});
python
api = apigateway.RestApi(self, "books-api")
api.add_gateway_response("test-response",
type=apigateway.ResponseType.ACCESS_DENIED,
status_code="500",
response_headers={
# Note that values must be enclosed within a pair of single quotes
"Access-Control-Allow-Origin": "'test.com'",
"test-key": "'test-value'"
},
templates={
"application/json": "{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }"
}
)
java
RestApi api = new RestApi(this, "books-api");
api.addGatewayResponse("test-response", GatewayResponseOptions.builder()
.type(ResponseType.ACCESS_DENIED)
.statusCode("500")
.responseHeaders(Map.of(
// Note that values must be enclosed within a pair of single quotes
"Access-Control-Allow-Origin", "'test.com'",
"test-key", "'test-value'"))
.templates(Map.of(
"application/json", "{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }"))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
var api = new RestApi(this, "books-api");
api.AddGatewayResponse("test-response", new GatewayResponseOptions {
Type = ResponseType.ACCESS_DENIED,
StatusCode = "500",
ResponseHeaders = new Dictionary<string, string> {
// Note that values must be enclosed within a pair of single quotes
{ "Access-Control-Allow-Origin", "'test.com'" },
{ "test-key", "'test-value'" }
},
Templates = new Dictionary<string, string> {
{ "application/json", "{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }" }
}
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
api := apigateway.NewRestApi(this, jsii.String("books-api"))
api.AddGatewayResponse(jsii.String("test-response"), &GatewayResponseOptions{
Type: apigateway.ResponseType_ACCESS_DENIED(),
StatusCode: jsii.String("500"),
ResponseHeaders: map[string]*string{
// Note that values must be enclosed within a pair of single quotes
"Access-Control-Allow-Origin": jsii.String("'test.com'"),
"test-key": jsii.String("'test-value'"),
},
Templates: map[string]*string{
"application/json": jsii.String("{ \"message\": $context.error.messageString, \"statusCode\": \"488\", \"type\": \"$context.error.responseType\" }"),
},
})
Properties
ACCESS_DENIEDResponseTypeACCESS_DENIEDResponseTypeACCESS_DENIEDResponseTypeACCESS_DENIEDResponseTypeACCESS_DENIEDResponseType static #The gateway response for authorization failure.
API_CONFIGURATION_ERRORResponseTypeAPI_CONFIGURATION_ERRORResponseTypeAPI_CONFIGURATION_ERRORResponseTypeAPI_CONFIGURATION_ERRORResponseTypeAPI_CONFIGURATION_ERRORResponseType static #The gateway response for an invalid API configuration.
AUTHORIZER_CONFIGURATION_ERRORResponseTypeAUTHORIZER_CONFIGURATION_ERRORResponseTypeAUTHORIZER_CONFIGURATION_ERRORResponseTypeAUTHORIZER_CONFIGURATION_ERRORResponseTypeAUTHORIZER_CONFIGURATION_ERRORResponseType static #The gateway response for failing to connect to a custom or Amazon Cognito authorizer.
AUTHORIZER_FAILUREResponseTypeAUTHORIZER_FAILUREResponseTypeAUTHORIZER_FAILUREResponseTypeAUTHORIZER_FAILUREResponseTypeAUTHORIZER_FAILUREResponseType static #The gateway response when a custom or Amazon Cognito authorizer failed to authenticate the caller.
BAD_REQUEST_BODYResponseTypeBAD_REQUEST_BODYResponseTypeBAD_REQUEST_BODYResponseTypeBAD_REQUEST_BODYResponseTypeBAD_REQUEST_BODYResponseType static #The gateway response when the request body cannot be validated according to an enabled request validator.
BAD_REQUEST_PARAMETERSResponseTypeBAD_REQUEST_PARAMETERSResponseTypeBAD_REQUEST_PARAMETERSResponseTypeBAD_REQUEST_PARAMETERSResponseTypeBAD_REQUEST_PARAMETERSResponseType static #The gateway response when the request parameter cannot be validated according to an enabled request validator.
DEFAULT_4XXResponseTypeDEFAULT_4_XXResponseTypeDEFAULT_4XXResponseTypeDEFAULT_4XXResponseTypeDEFAULT_4XXResponseType static #The default gateway response for an unspecified response type with the status code of 4XX.
DEFAULT_5XXResponseTypeDEFAULT_5_XXResponseTypeDEFAULT_5XXResponseTypeDEFAULT_5XXResponseTypeDEFAULT_5XXResponseType static #The default gateway response for an unspecified response type with a status code of 5XX.
EXPIRED_TOKENResponseTypeEXPIRED_TOKENResponseTypeEXPIRED_TOKENResponseTypeEXPIRED_TOKENResponseTypeEXPIRED_TOKENResponseType static #The gateway response for an AWS authentication token expired error.
INTEGRATION_FAILUREResponseTypeINTEGRATION_FAILUREResponseTypeINTEGRATION_FAILUREResponseTypeINTEGRATION_FAILUREResponseTypeINTEGRATION_FAILUREResponseType static #The gateway response for an integration failed error.
INTEGRATION_TIMEOUTResponseTypeINTEGRATION_TIMEOUTResponseTypeINTEGRATION_TIMEOUTResponseTypeINTEGRATION_TIMEOUTResponseTypeINTEGRATION_TIMEOUTResponseType static #The gateway response for an integration timed out error.
INVALID_API_KEYResponseTypeINVALID_API_KEYResponseTypeINVALID_API_KEYResponseTypeINVALID_API_KEYResponseTypeINVALID_API_KEYResponseType static #The gateway response for an invalid API key submitted for a method requiring an API key.
INVALID_SIGNATUREResponseTypeINVALID_SIGNATUREResponseTypeINVALID_SIGNATUREResponseTypeINVALID_SIGNATUREResponseTypeINVALID_SIGNATUREResponseType static #The gateway response for an invalid AWS signature error.
MISSING_AUTHENTICATION_TOKENResponseTypeMISSING_AUTHENTICATION_TOKENResponseTypeMISSING_AUTHENTICATION_TOKENResponseTypeMISSING_AUTHENTICATION_TOKENResponseTypeMISSING_AUTHENTICATION_TOKENResponseType static #The gateway response for a missing authentication token error, including the cases when the client attempts to invoke an unsupported API method or resource.
QUOTA_EXCEEDEDResponseTypeQUOTA_EXCEEDEDResponseTypeQUOTA_EXCEEDEDResponseTypeQUOTA_EXCEEDEDResponseTypeQUOTA_EXCEEDEDResponseType static #The gateway response for the usage plan quota exceeded error.
REQUEST_TOO_LARGEResponseTypeREQUEST_TOO_LARGEResponseTypeREQUEST_TOO_LARGEResponseTypeREQUEST_TOO_LARGEResponseTypeREQUEST_TOO_LARGEResponseType static #The gateway response for the request too large error.
RESOURCE_NOT_FOUNDResponseTypeRESOURCE_NOT_FOUNDResponseTypeRESOURCE_NOT_FOUNDResponseTypeRESOURCE_NOT_FOUNDResponseTypeRESOURCE_NOT_FOUNDResponseType static #The gateway response when API Gateway cannot find the specified resource after an API request passes authentication and authorization.
Valid value of response type.
THROTTLEDResponseTypeTHROTTLEDResponseTypeTHROTTLEDResponseTypeTHROTTLEDResponseTypeTHROTTLEDResponseType static #The gateway response when usage plan, method, stage, or account level throttling limits exceeded.
UNAUTHORIZEDResponseTypeUNAUTHORIZEDResponseTypeUNAUTHORIZEDResponseTypeUNAUTHORIZEDResponseTypeUNAUTHORIZEDResponseType static #The gateway response when the custom or Amazon Cognito authorizer failed to authenticate the caller.
UNSUPPORTED_MEDIA_TYPEResponseTypeUNSUPPORTED_MEDIA_TYPEResponseTypeUNSUPPORTED_MEDIA_TYPEResponseTypeUNSUPPORTED_MEDIA_TYPEResponseTypeUNSUPPORTED_MEDIA_TYPEResponseType static #The gateway response when a payload is of an unsupported media type, if strict passthrough behavior is enabled.
WAF_FILTEREDResponseTypeWAF_FILTEREDResponseTypeWAF_FILTEREDResponseTypeWAF_FILTEREDResponseTypeWAF_FILTEREDResponseType static #The gateway response when a request is blocked by AWS WAF.
Methods
of(type: string): ResponseType // chainable@staticmethod def of(type: str) -> ResponseTypepublic static ResponseType of(String type)public static ResponseType Of(string type)func Of(Type *string) ResponseType static #A custom response type to support future cases.