aws-cdk
aws-cdk copied to clipboard
Cannot call request validator options multiple times.
Calling the constructor for RequestValidatorOptions multiple times gives an error
There is already a Construct with name 'validator' in RestApi
Reproduction Steps
`
resource1.add_method(
http_method='POST',
integration=xxxIntegration,
request_parameters={
'method.request.header.passcode': True,
'method.request.header.message': True
},
request_validator_options=_apigw.RequestValidatorOptions(validate_request_parameters=True, request_validator_name='POST-r1-validator')
)
resource2.add_method(
http_method='POST',
integration=yyyIntegration,
request_parameters={
'method.request.header.passcode': True,
'method.request.querystring.id': True
},
request_validator_options=_apigw.RequestValidatorOptions(validate_request_parameters=True,request_validator_name='POST-r2-validator')
)
`
Error Log
Environment
- **CLI Version :1.35.1
- **Framework Version:1.35.1
- **OS : Mac Mojave
- **Language : Python
Other
This is :bug: Bug Report
Thanks for filing this @durja. This is, in fact, a bug on the CDK.
You can workaround this by using the requestValidator property.
The proposed solution is to remove the requestValidatorOptions property completely, And add in
const req = new apiGateway.RequestValidator(this, uniqueName, {
restApi: this._api,
requestValidatorName: uniqueName,
validateRequestBody: false,
validateRequestParameters: true
})
I can't actually create the new class object without it failing at the above line.
TypeError: Cannot read property 'children' of undefined
at synthNestedAssemblies (proj\cdk\node_modules\@aws-cdk\core\lib\private\synthesis.ts:50:33)
at synthNestedAssemblies (proj\cdk\node_modules\@aws-cdk\core\lib\private\synthesis.ts:54:7)
at synthNestedAssemblies (proj\cdk\node_modules\@aws-cdk\core\lib\private\synthesis.ts:54:7)
at synthNestedAssemblies (proj\cdk\node_modules\@aws-cdk\core\lib\private\synthesis.ts:54:7)
at Object.synthesize (proj\cdk\node_modules\@aws-cdk\core\lib\private\synthesis.ts:14:3)
at App.synth (proj\cdk\node_modules\@aws-cdk\core\lib\stage.ts:188:23)
at process.App.process.once (proj\cdk\node_modules\@aws-cdk\core\lib\app.ts:123:45)
at Object.onceWrapper (events.js:277:13)
at process.emit (events.js:189:13)
at process.EventEmitter.emit (domain.js:441:20)
@monkeytronics changing the implementation throws another error
Caused by: java.lang.NullPointerException: restApi is required
Hi folks, will this be fixed eventually?
I had to remove validation also :(
Was able to get around this by creating a validator object.
const queryStringValidator = new apigateway.RequestValidator(
scope,
"validator",
{
restApi: api,
requestValidatorName: "validator",
validateRequestBody: false,
validateRequestParameters: true,
}
);
resource.addMethod(
"GET",
new apigateway.LambdaIntegration(this.lambdaFunc),
{
requestParameters: {
"method.request.querystring.attribute": true,
},
requestValidator: queryStringValidator,
}
);
Not the most elegant solution, but here is what I'm using:
const getMethodOptions = (model?: Model): MethodOptions => {
const methodOptions: MethodOptions = {
authorizer: tokenAuthorizer,
requestParameters: {
"method.request.header.authorization": true,
},
requestModels: {},
// https://github.com/aws/aws-cdk/issues/7613
requestValidator: new RequestValidator(
this,
"AppApiRequestValidator" + this.requestValidatorSuffix,
{
restApi: appApi,
validateRequestParameters: true,
validateRequestBody: Boolean(model),
}
),
};
this.requestValidatorSuffix++;
if (model) {
return {
...methodOptions,
requestModels: { "application/json": model },
};
}
return methodOptions;
};
Hi there 👋
It has been about over a year and a half since this has been reported, what is the status on this?
Thanks!
This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.