Skip to content

(apigatewayv2): addRoutes doesn't allow authorizationType: 'AWS_IAM' #15123

Closed
@jasonwadsworth

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-apigatewayv2Related to Amazon API Gateway v2effort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions