aws-cdk-lib.aws_apigateway.RequestValidatorOptions

interface RequestValidatorOptions

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

Example

declare const integration: apigateway.LambdaIntegration;
declare const resource: apigateway.Resource;
declare const responseModel: apigateway.Model;
declare const errorResponseModel: apigateway.Model;

resource.addMethod('GET', integration, {
  // We can mark the parameters as required
  requestParameters: {
    'method.request.querystring.who': true
  },
  // we can set request validator options like below
  requestValidatorOptions: {
    requestValidatorName: 'test-validator',
    validateRequestBody: true,
    validateRequestParameters: false
  },
  methodResponses: [
    {
      // Successful response from the integration
      statusCode: '200',
      // Define what parameters are allowed or not
      responseParameters: {
        'method.response.header.Content-Type': true,
        'method.response.header.Access-Control-Allow-Origin': true,
        'method.response.header.Access-Control-Allow-Credentials': true
      },
      // Validate the schema on the response
      responseModels: {
        'application/json': responseModel
      }
    },
    {
      // Same thing for the error responses
      statusCode: '400',
      responseParameters: {
        'method.response.header.Content-Type': true,
        'method.response.header.Access-Control-Allow-Origin': true,
        'method.response.header.Access-Control-Allow-Credentials': true
      },
      responseModels: {
        'application/json': errorResponseModel
      }
    }
  ]
});

Properties

NameTypeDescription
requestValidatorName?stringThe name of this request validator.
validateRequestBody?booleanIndicates whether to validate the request body according to the configured schema for the targeted API and method.
validateRequestParameters?booleanIndicates whether to validate request parameters.

requestValidatorName?

Type: string (optional, default: None)

The name of this request validator.


validateRequestBody?

Type: boolean (optional, default: false)

Indicates whether to validate the request body according to the configured schema for the targeted API and method.


validateRequestParameters?

Type: boolean (optional, default: false)

Indicates whether to validate request parameters.