-
Notifications
You must be signed in to change notification settings - Fork 4.5k
(apigatewayv2): addRoutes doesn't allow authorizationType: 'AWS_IAM' #15123
Copy link
Copy link
Closed
Labels
@aws-cdk/aws-apigatewayv2Related to Amazon API Gateway v2Related to Amazon API Gateway v2effort/mediumMedium work item – several days of effortMedium work item – several days of effortfeature-requestA feature should be added or improved.A feature should be added or improved.p2
Description
The L2 construct doesn't yet support IAM auth, so as a work around I had included the following code:
export class HttpIamAuthorizer implements IHttpRouteAuthorizer {
public bind(_: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfig {
return {
// @ts-ignore
authorizationType: 'AWS_IAM',
};
}
}This allowed me to do an addRoutes that looked something like this:
httpApi.addRoutes({
integration: new LambdaProxyIntegration({
handler: api.alias
}),
authorizer: new HttpIamAuthorizer(),
methods: [HttpMethod.GET],
path: '/somepath'
});...which resulted in CloudFormation like this:
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "HttpApiF5A9A8A7"
},
"RouteKey": "POST /somepath",
"AuthorizationType": "AWS_IAM",
"Target": {
"Fn::Join": [
"",
[
"integrations/",
{
"Ref": "Integration"
}
]
]
}
}When updating my CDK to the latest this no longer works due to this line of code:
| if (authBindResult && !(authBindResult.authorizationType in HttpRouteAuthorizationType)) { |
Reproduction Steps
Create this class:
export class HttpIamAuthorizer implements IHttpRouteAuthorizer {
public bind(_: HttpRouteAuthorizerBindOptions): HttpRouteAuthorizerConfig {
return {
// @ts-ignore
authorizationType: 'AWS_IAM',
};
}
}and addRoutes like this:
httpApi.addRoutes({
integration: new LambdaProxyIntegration({
handler: api.alias
}),
authorizer: new HttpIamAuthorizer(),
methods: [HttpMethod.GET],
path: '/somepath'
});What did you expect to happen?
Given that AWS_IAM is valid for the L1 construct I would expect that the validation would allow it.
What actually happened?
An error is thrown, and the stack will not synth
Environment
- CDK CLI Version : 1.108.1
- Framework Version: 1.108.1
- Node.js Version: 12
- OS :
- Language (Version):
This is 🐛 Bug Report
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-apigatewayv2Related to Amazon API Gateway v2Related to Amazon API Gateway v2effort/mediumMedium work item – several days of effortMedium work item – several days of effortfeature-requestA feature should be added or improved.A feature should be added or improved.p2