11

I am using the amplify framework from AWS to build a webapp in Vue.js.

As for now, I am using the cognito service to authenticate users.

I want to trigger a lambda function when the user first create his account. I already created a lambda function using the following command:

amplify function add

I tested my function using this command:

amplify function invoke myLambdaFunction

And now I want to trigger this function when an user create an account.

Any idea how can I do that ?

Thank you, Alexis

Alexis Santini
  • 331
  • 1
  • 3
  • 17

2 Answers2

15

You can do it with the cli:

% amplify auth update
What do you want to do? Walkthrough all the auth configurations
...
? Do you want to configure Lambda Triggers for Cognito? Yes 
? Which triggers do you want to enable for Cognito Pre Sign-up
? What functionality do you want to use for Pre Sign-up
Do you want to edit your custom function now? Yes

Then you can add your logic in this newly generated function

Engam
  • 1,051
  • 8
  • 17
7

I was able to create a trigger using these options: See Docs

$ amplify auth update

? 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, connected with AWS IAM controls (Enables per-user Storage features fo
r images or other content, Analytics, and more)
? Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM) No
? Do you want to enable 3rd party authentication providers in your identity pool? No
? Do you want to add User Pool Groups? No
? Do you want to add an admin queries API? No
? Multifactor authentication (MFA) user login options: OPTIONAL (Individual users can use MFA)
? For user login, select the MFA types: SMS Text Message
? Please specify an SMS authentication message: Your authentication code is {####}
? Email based user registration/forgot password: Enabled (Requires per-user email entry at registration)
? Please specify an email verification subject: Your verification code
? Please specify an email verification message: Your verification code is {####}
? Do you want to override the default password policy for this User Pool? No
? Specify the app's refresh token expiration period (in days): 120
? Do you want to specify the user attributes this app can read and write? No
? Do you want to enable any of the following capabilities? 
? Do you want to use an OAuth flow? No
? Do you want to configure Lambda Triggers for Cognito? Yes
? Which triggers do you want to enable for Cognito 
O.O
  • 1,389
  • 14
  • 29
  • You can press Enter w/o any value entered, and it will record current value. You can also look at existing CLI config for reference (to prevent unintended change): `amplify/backend/auth/.../cli-inputs.json` – Emre Dec 14 '22 at 17:52
  • When I get to this step to enable triggers, no functions are actually created for me. It just has an empty object in for the triggers key (`"triggers": {}`) in my `cli-inputs.json`. What is the expected output when you say "yes" and select the triggers to enable? – pmm4654 Aug 06 '23 at 00:55