amplify-cli: How to add a pre or post SignUp hook/trigger?

** Which Category is your question related to? ** Auth / Functions

** What AWS Services are you utilizing? ** Cognito, Lambda, Amplify Console

** Provide additional details e.g. code snippets ** Once a user has signed up I’d like to execute a Function (Lambda) to modify their User Pool entry (in my case to set custom:tenant_id to a GUID). It isn’t clear to me how I would do this.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 22 (7 by maintainers)

Most upvoted comments

Be nice to kick off any lambda function you want at points in the auth workflow. I would like to be able to kick off a Lambda after account verification that goes and adds some data into my DB. As far as I can tell that’s not possible.

Absolutely agree on this one!

Right now I’m struggling with amplify update auth to add Lambda Triggers. It asks all the questions again. I wish amplify update auth showed Add/Update lambda triggers on the top menu e.g.

$ amplify auth update

Using service: Cognito, provided by: awscloudformation
 What do you want to do? (Use arrow keys)
❯ Apply default configuration without Social Provider (Federation)
  Walkthrough all the auth configurations
  Add/Edit signin and signout redirect URIs
  Update OAuth social providers
  Add/Update lambda triggers                 // ***** something like this *****
  Create or update Cognito user pool groups
  Create or update Admin queries API

@mbecker when I added a trigger, I go through all the walkthrough questions then do a diff on the cloudformation files to double check what the walkthrough did and what my setup had before. Often times I have to revert some of the things the walkthrough did, especially if you modified parameters.json or the cloudformation files outside the walkthrough to get features the walkthrough does not support (e.g. user name case insensitivity)

@troygoode @ovandr we are investigating a project to make advanced admin features like this, such as setting up Lambda triggers from template samples and such, available in the CLI. I have reopened this issue and tagged it as part of the project: https://github.com/aws-amplify/amplify-cli/projects/1 There will be an RFC soon in the repo for you to give feedback on requirements. Stay tuned.

@troygoode You need setup a lambda function and add that in your Cognito User Pool. The doc: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-post-confirmation.html

Going through all the steps to add a trigger is not the best approach. It often ruins current settings. Is possible to just add a trigger and do not change anything else for auth?

Thanks @powerful23 @kaustavghosh06; I suppose what I’m wondering is how to do so in a way that works well with a Amplify CLI multienv setup. Namely I’m concerned about how to do this without having to hard-code the Pool ARN or Lambda ARN in such a way that another developer on our team running amplify env checkout <branch> won’t work.

My understanding is add lambda triggers after the auth module has been created is still to re-run Walkthrough all the auth configurations. I mean at this point:

What do you want to do? Walkthrough all the auth configurations
 Select the authentication/authorization services that you want to use: User Sign-Up & Sign-In only (Best used with a cloud API only)
 Do you want to add User Pool Groups? Yes
? Provide a name for your user pool group: 

I’m unclear if that action would delete my existing user pool - when I only wanted to add a lambda trigger.

Hi @powerful23 . I want to share my Amplify project with over developers. Now it takes 3 steps to deploy own replica of the application: 1) clone repo 2) run amplify init 3) run amplify publish.

It seems that it’s impossible to add lambda function in Cognito User Pool using amplify-cli. So over developers need to perform additional steps in Amazon Console to define pre/post SignUp handlers.

I think it will be useful to have this feature in amplify-cli. This will allow us to implement things like Auto-Confirm Users

@mark-a-bailey it sounds like you’ve figured out the cli steps on how to get to the menu that allows you to add triggers. Can you share the CLI/choice steps?

Be nice to kick off any lambda function you want at points in the auth workflow. I would like to be able to kick off a Lambda after account verification that goes and adds some data into my DB. As far as I can tell that’s not possible.

Absolutely agree on this one!

Right now I’m struggling with amplify update auth to add Lambda Triggers. It asks all the questions again. I wish amplify update auth showed Add/Update lambda triggers on the top menu e.g.

$ amplify auth update

Using service: Cognito, provided by: awscloudformation
 What do you want to do? (Use arrow keys)
❯ Apply default configuration without Social Provider (Federation)
  Walkthrough all the auth configurations
  Add/Edit signin and signout redirect URIs
  Update OAuth social providers
  Add/Update lambda triggers                 // ***** something like this *****
  Create or update Cognito user pool groups
  Create or update Admin queries API

Hi guys, any chance to just add the lambda triggers / functions to an existing Auth? To be honest I’m struggeling to answer all these question I’ve answered already some time ago.

In the meantime I see in file of ‘…/amplify/backend/auth/appname/parameters.json’ the following syntax for the triggers:

{
    ...
    "triggers": "{}",
    "userPoolGroupList": [],
    "parentStack": {
        "Ref": "AWS::StackId"
    },
    "permissions": [],
    "dependsOn": []
}

Does anyone maybe know to add the triggers manually? How does the file ‘parameters.json’ looks like for automatically added triggers?

Thanks for your help!

There are some more docs here…

https://aws-amplify.github.io/docs/cli-toolchain/cognito-triggers

Be nice to kick off any lambda function you want at points in the auth workflow. I would like to be able to kick off a Lambda after account verification that goes and adds some data into my DB. As far as I can tell that’s not possible.