Issue with AWS Polly Integration in .net: AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service #3321
-
I'm integrating AWS Polly (TTS) into my Unity game and wrote the following code: public AwsPollyAPIClient(AwsPollyCredentials pollyCredentials, Amazon.RegionEndpoint regionEndpoint)
{
this._pollyCredentials = pollyCredentials;
this._regionEndpoint = regionEndpoint;
var credentials = new SessionAWSCredentials(pollyCredentials.AccessKeyId, pollyCredentials.SecretAccessKey, pollyCredentials.SessionToken);
var client = new Amazon.Polly.AmazonPollyClient(credentials, _regionEndpoint);
} I am confident that the session-based AWS credentials are correct because they work when tested with Postman (screenshot below): However, when I run this code, I encounter an AmazonServiceException with the following error message:
Additional Information:AWS SDK Code Version: 3.7.304.3 The error message is: "AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service." What does this even mean? I've tested my session-based credentials via Postman, and they work fine. Does the AWS SDK assume something behind the scenes? Should I write custom code to sign the AWS request and call the AWS Polly API directly instead? Please help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
-
@Johnny850807 Good afternoon. Your code doesn't appear to be correct. You are creating Did you instead intended to assign the Thanks, |
Beta Was this translation helpful? Give feedback.
@Johnny850807 Good afternoon. Your code doesn't appear to be correct. You are creating
Amazon.Polly.AmazonPollyClient
object and assigning to local variable in the constructor, which gets destroyed once the constructor method finishes execution. Although I do not have access to your code, yourAwsPollyAPIClient.SynthesizeSpeech
API method doesn't use this object and appears to use a defaultAmazon.Polly.AmazonPollyClient
without any credentials parameter, which results in AWS .NET SDK doing the credential resolution per Credential and profile resolution, ultimately failing atAmazon EC2 instance metadata
.Did you instead intended to assign the
Amazon.Polly.AmazonPollyClient
that you creat…