Skip to content

@aws-cdk/aws-apigatewayv2:setting one authorizer for many routes is patchy #20170

Open
@mat01

Description

@mat01

Describe the bug

I have a HTTP api with two groupings of routes.

For one grouping, I'm using a Cognito authorizer.

The authorizer is defined like this :

const Auth1 = new apiGatewayAuthorizers.HttpUserPoolAuthorizer('auth1', userPool, {userPoolClients: [userPoolClient],identitySource: ['$request.header.Authorization']});

and I apply it to a route like this :

httpApi.addRoutes({ path: '/route',methods: [ apigwv2.HttpMethod.POST ], integration: myIntegration, authorizer:Auth1});

With this 'first group' of routes, I initially had problems applying this authorizer to more than one route. Bizarrely, changing the const name from 'CognitoAuthorizer' to 'Auth1' seemed to allow me to do this?!

Now I am on to my second group of routes (on the same API), this time using a standard api-key based authorizer (Auth2).

This is defined as

const Auth2 = new apiGatewayAuthorizers.HttpLambdaAuthorizer('auth2b',backLambdas.backendAuthorizer,{identitySource: ['$request.header.Authorization'],resultsCacheTtl:cdk.Duration.minutes(1)});

Again, I have the same error message that I originally got with Auth1.

Authorizer name must be unique. Authorizer auth2b already exists in this RestApi.

Expected Behavior

I expect to be allowed to use one authorizer for multiple routes

Current Behavior

I am prevented from using one authorizer for multiple routes with the error message

Authorizer name must be unique. Authorizer auth2b already exists in this RestApi.

Reproduction Steps

cdk deploy

Possible Solution

The problem seems to be centred around names and ids of resources within the CDK.

Additional Information/Context

No response

CDK CLI Version

2.21.1

Framework Version

No response

Node.js Version

v16.14.2

OS

windows powershell

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-apigatewayv2-authorizersRelated to aws-apigatewayv2-authorizers packagebugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions