question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-cognito): Cannot re-use same lambda as lambdaTriggers for different Cognito

See original GitHub issue

Hi 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:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sasheecommented, Oct 14, 2022

It’s still an issue

0reactions
github-actions[bot]commented, Oct 14, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing user pool workflows with Lambda triggers
Customize Amazon Cognito user pool workflows with AWS Lambda triggers. ... For some actions, federated users invoke more than one Lambda function.
Read more >
How to access Cognito Userpool from inside a lambda function?
On the file, search for the lambdaexecutionpolicy , and then PolicyDocument inside it. Add your required permission under Statement :
Read more >
Send AWS Cognito emails with 3rd party ESPs
Below is a guide to deploying and using these new Cognito Lambda triggers. We will see how to deploy them with Cloudformation and...
Read more >
Authentication with AWS Cognito ⋆ Mark McDonnell - integralist
Just something to consider when using Cognito: can I use lambda triggers to improve the user flow? Social Logins. One thing that might...
Read more >
Cognito Triggers Deep Dive — PreSignUp | Level Up Coding
A deep-dive into the AWS Cognito PreSignUp trigger source with tips, use-cases and ... This article is part of the Cognito Lambda Triggers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found