Friday, 16 July 2021

Amazon Simple Email Service, Credential should be scoped to correct service: 'email'

  1. In first step I created an Identity Pool in Cognito
  2. Enable access to unauthenticated identities
  3. Added an Unauthenticated role with following configuration.
    {
     "Version": "2012-10-17",
     "Statement": [
     {
      "Effect": "Allow",
      "Action": [
        "cognito-sync:*",
        "ses:SendEmail"
      ],
      "Resource": [
        "*"
       ]
      }
     ]
    }

then in Android studio I Added the following SDK for amazon.

implementation 'com.amazonaws:aws-android-sdk-core:2.26.0'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.20.1'
implementation 'com.amazonaws:aws-android-sdk-ses:2.20.1'

After I initialized Amazon SES using cognito like this:

     val credentials = CognitoCachingCredentialsProvider(
            context, // CONTEXT
            "us-east-1:your_identify_pool", // IDENTITY POOL ID
            Regions.US_EAST_1 // REGION
        )
        
        val ses = AmazonSimpleEmailServiceClient(credentials)
        ses?.setRegion(Region.getRegion(Regions.US_EAST_1))
        ses?.endpoint = "email.us-east-1.amazonaws.com"

Next sending email using SES client:

 val request = SendEmailRequest(email.from, destination, message)
 ses.sendEmail(request)

when i run this i got the following exception

com.amazonaws.AmazonServiceException: Credential should be scoped to 
correct service: 'email'. (Service: AmazonSimpleEmailService; Status 
Code: 403; Error Code: SignatureDoesNotMatch; Request ID: 5bd493a7-0184- 
49e6-bc03-5b95386d5b20)


from Amazon Simple Email Service, Credential should be scoped to correct service: 'email'

No comments:

Post a Comment