Get Instant Solutions for Kubernetes, Databases, Docker and more
Amazon Cognito is a robust authentication service provided by AWS that allows developers to add user sign-up, sign-in, and access control to their web and mobile applications quickly and securely. It supports social identity providers like Facebook, Google, and Amazon, as well as enterprise identity providers via SAML 2.0 and OpenID Connect.
When using Amazon Cognito, you might encounter the InvalidSmsRoleTrustRelationshipException
. This error typically manifests when attempting to send SMS messages for multi-factor authentication or user verification, and the operation fails unexpectedly.
This exception indicates that there is an issue with the trust relationship of the IAM role that Amazon Cognito uses to send SMS messages. Specifically, the trust policy does not allow Cognito to assume the role, which is necessary for sending SMS messages.
The root cause of this issue is an incorrect trust relationship policy in the IAM role associated with SMS messaging. Without the correct permissions, Cognito cannot assume the role, leading to the error.
Navigate to the AWS IAM Console and sign in with your AWS credentials.
In the IAM console, find the role associated with your Amazon Cognito user pool that is responsible for sending SMS messages.
Click on the role to view its details, then select the "Trust relationships" tab. Edit the trust policy to include the following JSON snippet:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "cognito-idp.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
This policy allows the Cognito Identity Provider service to assume the role.
After updating the trust relationship, save the changes. Test the SMS functionality in your application to ensure that the issue is resolved.
For more detailed information, refer to the AWS Cognito SMS Setup Guide and the AWS IAM Role Management Documentation.
(Perfect for DevOps & SREs)
Try Doctor Droid — your AI SRE that auto-triages alerts, debugs issues, and finds the root cause for you.