aws-cdk-lib.aws_apigateway.GatewayResponseOptions

interface GatewayResponseOptions

LanguageType name
.NETAmazon.CDK.AWS.APIGateway.GatewayResponseOptions
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#GatewayResponseOptions
Javasoftware.amazon.awscdk.services.apigateway.GatewayResponseOptions
Pythonaws_cdk.aws_apigateway.GatewayResponseOptions
TypeScript (source)aws-cdk-lib » aws_apigateway » GatewayResponseOptions

Options to add gateway response.

Example

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

Properties

NameTypeDescription
typeResponseTypeResponse type to associate with gateway response.
responseHeaders?{ [string]: string }Custom headers parameters for response.
statusCode?stringHttp status code for response.
templates?{ [string]: string }Custom templates to get mapped as response.

type

Type: ResponseType

Response type to associate with gateway response.

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


responseHeaders?

Type: { [string]: string } (optional, default: no headers)

Custom headers parameters for response.


statusCode?

Type: string (optional, default: standard http status code for the response type.)

Http status code for response.


templates?

Type: { [string]: string } (optional, default: Response from api will be returned without applying any transformation.)

Custom templates to get mapped as response.