Deepak
Deepak

Reputation: 301

Post Confirmation doesn't trigger lambda function

My step:

Upvotes: 12

Views: 3422

Answers (4)

staxdflow
staxdflow

Reputation: 33

I believe Ragav's answer is the closest one but missing some extra information. For pre-signup triggers, you run the risk that Cognito denies the registration after you already synced the user to the database. So keep the syncing in the Post-Confirmation trigger.

Add a pre-signup trigger that only listens for "AdminCreateNewUser" type of events, since these are the edge case anyways, and then you can safely add these users to the DB since Cognito won't give any validation problems afterwards for these specific users.

This is the event that the pre-signup trigger passes:

    {
      "version": "1",
      "region": "us-east-1",
      "userPoolId": "us-east-1_xxxxxxxx",
      "userName": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "callerContext": {
        "awsSdkVersion": "aws-sdk-js-2.1545.0",
        "clientId": "CLIENT_ID_NOT_APPLICABLE"
      },
      "triggerSource": "PreSignUp_AdminCreateUser",
      "request": {
        "userAttributes": {
          "email": "[email protected]"
        },
        "validationData": null
      },
      "response": {
        "autoConfirmUser": false,
        "autoVerifyEmail": false,
        "autoVerifyPhone": false
      }
    }

Upvotes: 1

Sandeep
Sandeep

Reputation: 357

As the name suggests, it is post "confirmation" trigger. The user needs to confirm the email belongs to him/her. This is done by entering the OTP that cognito sends to the given email address. Once the user enters that OTP, the email address is confirmed and post confirmation trigger fires.

Do Use the hosted UI's "Signup" link to create the account

Do Not Use Cognito service's in-built user creation page. Use Admin API

Upvotes: 0

Ragav Y
Ragav Y

Reputation: 1872

I am looking for the answer to this as well and I found this in the official documentation:-

You create custom workflows by assigning AWS Lambda functions to user pool triggers. When you use the AdminCreateUser API action, Amazon Cognito invokes the function that is assigned to the pre sign-up trigger. When Amazon Cognito invokes this function, it passes a JSON payload, which the function receives as input.

So basically we need to attach the lambda function to the pre sign-up trigger if we are using the AdminCreateUser API action. Haven't checked if it works. Confirmation would be great!

Update:-

I tried it out myself and it does trigger the pre sign-up lambda function. So there's the confirmation!

Upvotes: 2

Subash
Subash

Reputation: 7266

Cognito does not trigger post confirm when the user is created with adminCreateUser or manually from Cognito dashboard.

Upvotes: 9

Related Questions