aws/aws-cdk

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

Open

#20170 opened on May 2, 2022

View on GitHub
 (4 comments) (0 reactions) (0 assignees)TypeScript (10,710 stars) (3,530 forks)batch import
@aws-cdk/aws-apigatewayv2-authorizersbugeffort/smallgood first issuep2

Description

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

Contributor guide