Skip to content

aws-apigateway: requestValidatorOptions does not create validator #29834

Open
@anneadb

Description

@anneadb

Describe the bug

I am trying to add a request validator to my Lambda proxy API. I am setting requestValidatorOptions in defaultMethodOptions but no validator is being created and added to the methods.
In the UI/console I can add a validation to the "ANY" method which is automatically created as part of LambdaRestApi.

Is there another way to add the validator to the proxy?

Expected Behavior

Validator is created and added to all methods.

Current Behavior

The cloudformation template shows the RequestParameters but no validator. Adding requestValidatorOptions is not recognized as a change during deployment.

Reproduction Steps

Create an api gateway using LambdaRestApi:

new apigateway.LambdaRestApi(this, "LambdaRestApi", {
      restApiName: `${env.project}-${subProjectName}-${env.deployer}`,
      handler: lambdaFunction,
      deployOptions: {
        loggingLevel: apigateway.MethodLoggingLevel.INFO,
        accessLogDestination: new apigateway.LogGroupLogDestination(logGroup),
        accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields(),
      },
      defaultMethodOptions: {
        apiKeyRequired: true,
        requestParameters: {
          "method.request.querystring.name": true,
          "method.request.querystring.env": false,
        },
        requestValidatorOptions: {
          requestValidatorName: "DefaultValidator",
          validateRequestParameters: true,
        },
      },
      endpointTypes: [apigateway.EndpointType.REGIONAL],
    })

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.122.0

Framework Version

No response

Node.js Version

v20.10.0

OS

macOS 14.4.1

Language

TypeScript

Language Version

No response

Other information

"AWS::ApiGateway::Method" from template.json:

"ApiGatewaySetupLambdaRestApiproxyANYF9A30FCD": {
   "Type": "AWS::ApiGateway::Method",
   "Properties": {
    "ApiKeyRequired": true,
    "AuthorizationType": "NONE",
    "HttpMethod": "ANY",
    "Integration": {
     "IntegrationHttpMethod": "POST",
     "Type": "AWS_PROXY",
     "Uri": {
      "Fn::Join": [
       "",
       [
        "arn:aws:apigateway:eu-central-1:lambda:path/2015-03-31/functions/",
        {
         "Fn::GetAtt": [
          "LambdaSetuplambdaE27E4408",
          "Arn"
         ]
        },
        "/invocations"
       ]
      ]
     }
    },
    "RequestParameters": {
     "method.request.querystring.name": true,
     "method.request.querystring.env": false
    },
    "ResourceId": {
     "Ref": "ApiGatewaySetupLambdaRestApiproxyD538D22D"
    },
    "RestApiId": {
     "Ref": "ApiGatewaySetupLambdaRestApi68D08033"
    }
   },
   "Metadata": {
    "aws:cdk:path": "MyStack/ApiGatewaySetup/LambdaRestApi/Default/{proxy+}/ANY/Resource"
   }
  },

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-apigatewayRelated to Amazon API GatewaybugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions