@aws-cdk/aws-apigatewayv2:setting one authorizer for many routes is patchy
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
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
Research direction
Reproduce the issue with AWS CDK 2.21.1 using one HttpUserPoolAuthorizer and one HttpLambdaAuthorizer across multiple HttpApi routes, then run cdk deploy. Trace how the authorizer names and IDs are handled for those routes; done means one authorizer can be applied to multiple routes without the duplicate-name error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100