How to send different verification emails at the same cognito user pool

Viewed 509

I'm using amazon-cognito for my application user access. I have two different groups inside my user pool. I want to send differenet email to each user depends on the group he belongs to.

The problem is that the email verification is sent when the user is created at the pool and not after he's linked to a group.

Is there a way do to it? Any help? advices?

1 Answers

After a lot of digging, I've figured out a solution. The solution is to use AWS Cognito Lambda.

Use AWS Cognito Lambda for SignUp or AdminCreateUser events depends on your application architecture. When a user is created either with SignUp or AdminCreateUser functions, there's an option to pass metadata with clientMetadata entry at the object.

For example (from AWS Docs):

{
   "ClientMetadata": { 
      "string" : "string" 
   },
   "DesiredDeliveryMediums": [ "string" ],
   "ForceAliasCreation": boolean,
   "MessageAction": "string",
   "TemporaryPassword": "string",
   "UserAttributes": [ 
      { 
         "Name": "string",
         "Value": "string"
      }
   ],
   "Username": "string",
   "UserPoolId": "string",
   "ValidationData": [ 
      { 
         "Name": "string",
         "Value": "string"
      }
   ]
}

According to docs:

clientMetadata

One or more key-value pairs that you can provide as custom input to the Lambda function that you specify for the pre sign-up trigger. You can pass this data to your Lambda function by using the ClientMetadata parameter in the following API actions: AdminCreateUser, AdminRespondToAuthChallenge, ForgotPassword, and SignUp.

So, pass the group inside the clientMetadata as an entry:

"ClientMetadata": { 
    "Group": "MyNiceGroup" 
},
...

Inside the lambda implementation, according to the incoming group decide which email to dispatch.

Related