Creating the Confirmation Lambda
Login to your AWS Console and search for Lambda in the search bar.
Create a new function.
Now open the AWS SDK documentation for Cognito Identity Provider.
Copy the import statement and paste it inside the Lambda function.
For the client, replace config with a pair of curly brackets and put region, colon, and the region you are in.
Now delete everything in the input except for the required ones.
The ClientId is for a Cognito User pool app client id.
Select the User pool. Go to App integration and scroll down to the App clients section.
Select the app client and use the client id in the lambda function.
For the username, type event, followed by square brackets, and “username” inside them. The ConfirmationCode would be the same but with confirmationCode inside.
Testing
To test this, click on the arrow next to the test button and select Configure test event.
Give the event a name like ConfirmationTest.
Save and go back to Cognito.
Then go back to the CreateAccount lambda. Click Test to create the account again.
You should receive a email with the confirmation code.
Now back to the ConfirmAccount lambda and edit the test configuration by setting the confirmationCode with the code you received.
Save, and if we click on “Test,” we should get a successful attempt since the status code is 200.
If we go back to the Users tab in Cognito, we should see that the email is verified and the confirmation status is confirmed.
That’s all for this tutorial. In the next one, we’ll create the lambda function for signing in.