(aws-cognito): Cannot re-use same lambda as lambdaTriggers for different Cognito
See original GitHub issueHi there,
I’m currently using CDK in typescript, but have some issues with lambdaTriggers.
My project is using multiple cognito user pools in order to manage multi-tenancy.
In order to manage the multi-tenancy, I need to override the JWT token key generated by Cognito, for that I would like to use the preTokenGeneration trigger.
I created my lambda in CDK and can easily attach it to one cognito user pool
However, it fails when I try to attach the same lambda to different cognito user pools.
Reproduction Steps
You can find my code to reproduce the issue here
https://github.com/jerome-comtylink/cdk-cognito-lambda
Or the code used in order to reproduce the issue
const fn = new Function(this, 'MyFunction', {
runtime: Runtime.NODEJS_12_X,
handler: 'index.handler',
code: Code.fromInline('exports.handler = function(event, ctx, cb) { return cb(null, "hello world"); }')
});
new UserPool(this, `userpool-1`, {
userPoolName: 'userpool',
accountRecovery: AccountRecovery.EMAIL_ONLY,
autoVerify: {
email: true,
},
lambdaTriggers: {
preTokenGeneration: fn,
},
});
const userPool = new UserPool(this, `userpool-2`, {
userPoolName: 'userpool',
accountRecovery: AccountRecovery.EMAIL_ONLY,
autoVerify: {
email: true,
},
lambdaTriggers: {
preTokenGeneration: fn,
},
});
What did you expect to happen?
Be able to attach the same lambda to multiple user pools
What actually happened?
cdk synth
is failing with the following error message
There is already a Construct with name 'PreTokenGenerationCognito' in Function [MyFunction]
Subprocess exited with error 1
Environment
- cdk version: 1.117.0 (build 0047c98)
- node: v12.22.1
- OS: Mac OS
- Typescript: Version 4.2.4
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
It’s still an issue
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.