GatewayResponseOptions

class aws_cdk.aws_apigateway.GatewayResponseOptions(*, type, response_headers=None, status_code=None, templates=None)

Bases: object

Options to add gateway response.

Parameters:
  • type (ResponseType) – Response type to associate with gateway response.

  • response_headers (Optional[Mapping[str, str]]) – Custom headers parameters for response. Default: - no headers

  • status_code (Optional[str]) – Http status code for response. Default: - standard http status code for the response type.

  • templates (Optional[Mapping[str, str]]) – Custom templates to get mapped as response. Default: - Response from api will be returned without applying any transformation.

ExampleMetadata:

infused

Example:

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" }"
    }
)

Attributes

response_headers

Custom headers parameters for response.

Default:
  • no headers

status_code

Http status code for response.

Default:
  • standard http status code for the response type.

templates

Custom templates to get mapped as response.

Default:
  • Response from api will be returned without applying any transformation.

type

Response type to associate with gateway response.

See:

https://docs.aws.amazon.com/apigateway/latest/developerguide/supported-gateway-response-types.html