Sitemap

Integrating SES with AWS Cognito

4 min readJul 27, 2024

--

Cognito sends only 50 emails per day for verifying users, what if you need to send 1000 email a day? AWS SES is your solution!!

AWS Simple Mail Service( SES ) is a cloud based email sending service that helps in sending email for verification email, password reset, OTP and transactional emails etc.

In my previous blog we have seen how to configure user pool in cognito and came across SES option in Cognito. Today we will see how to configure SES and integration it with Cognito.

Note: I have already created cognito user pool.

Step: 1 Open the SES service in AWS account and click on Get Started.

Press enter or click to view image in full size

Provide the email id with which you have to send emails to customers. You should have access to it for verification and click on Next.

Press enter or click to view image in full size
Provide email id

Step:2 Provide the Domain name of your application and click on Next.

Press enter or click to view image in full size
Provide domain name

Step: 3 If you want to send email from different mail, mention that subdomain here,

Press enter or click to view image in full size
Mail subdomain

Step: 4 Review all configurations and click on Get Started,

Press enter or click to view image in full size

Post configuring the SES, you will land on his page:

  • Sandbox(default): After the configuration first of all we will be in Sandbox environment by default and it has certain limitations.
Press enter or click to view image in full size
  • Email/Domain Verification(Mandatory): An email verification link is sent to above mentioned email and domain, please verify both. Without verification, you cannot send email to your customers with this email.
Press enter or click to view image in full size

Click on the link for verification,

Press enter or click to view image in full size

Congratulations! message show successful verification of an email.

Press enter or click to view image in full size

On SES dashboard, in Identities we can see status will be changed.

Press enter or click to view image in full size
email is verified

Limitations of SES Sandbox Env:

  • We can only send 200 emails in 24 hours.
  • can only send 1 email per second.
  • To send our customers OTP email(for example), their email should be verify beforehand and that is not possible when we have 1000s of users. If their email is not verified they will not receive any verification email/otp/password reset mails.

What to do in this case ?

Click on Request production access , fill all the details with your use case and it will open a ticket with AWS Support. Within 24 hours you will get production access.

Press enter or click to view image in full size

Integration with Cognito

  • Go to AWS cognito, user pool and click on Messaging field. Currently our cognito is configured with Send email with Cognito, click on Edit
Press enter or click to view image in full size
  • Select Send email with Amazon SES and in From email address, select the email that we verified earlier in SES. It will automatically appear post refreshing it and click on Save changes
Press enter or click to view image in full size

Let’s do the testing !!

We will register a user in cognito application and cognito will send a verification email via SES. We will check FROM email address field that our user will receive for otp,

  • Taking shreehan.kolbey@dockstones.com email as customer name
 aws cognito-idp sign-up --client-id 6fh1t8naq3clfp1db429ilhk1i --username user101 --password P@ssw0rd1 --user-attributes Name="email",Value="shreehan.kolbey@dockstones.com" Name="name",Value="user101" --region us-east-1
{
"UserConfirmed": false,
"CodeDeliveryDetails": {
"Destination": "s***@d***",
"DeliveryMedium": "EMAIL",
"AttributeName": "email"
},
"UserSub": "c458a4a8-7081-709e-b884-c5556723a89b"

Our customer has received verification code/OTP from wivob32276@bacaki.com email that we had registered in SES.

Press enter or click to view image in full size

Copy the code and verify the customer.

Verification code
aws cognito-idp --region us-east-1 confirm-sign-up --client-id 6fh1t8naq3clfp1db429ilhk1i --username=user101 --confirmation-code 973778

Our Customer is verified..

Press enter or click to view image in full size

Stay tuned for more blogs!!!

References:

Disposable email: https://www.disposablemail.com/

https://docs.aws.amazon.com/ses/latest/dg/setting-up.html

--

--

Anjali
Anjali

Written by Anjali

Security Engineer | Specialist in Cloud & DevSecOps Automation | Trainer @Blackhat/Nullcon/Bsides/CSA | Cloud Security Coach | OWASP EKS Goat Project Lead