Running this code in console application is working but not in webAPI project .netCore6 with docker container.
I’m getting
"Unable to get IAM security credentials from EC2 Instance Metadata Service." Error.
var region = RegionEndpoint.EUWest1;
var client = new AmazonCognitoIdentityProviderClient(region);
var request = new ListGroupsRequest
{
UserPoolId = "MyUserPoolID"
};
var response = await client.ListGroupsAsync(request);
Any help?
Thanks
2
Answers
The issue is your credentials are not being located within the container. You need to make sure that your credentials are available. One way is you can use an environment variable crendential provider and set both the key and secret key when you start your docker container.
To start docker container and specify keys:
docker run -e AWS_ACCESS_KEY_ID=AKIxxxxxxxxxxxxxx -e AWS_SECRET_ACCESS_KEY=K3Oxxxxxxxxxxxxxxxxxxxx -it getting-started /bin/bash
Then use the .NET environment variable cred provider.
Issue
When you run your application without docker, .NET SDK for AWS loads the credentials from the credential file located at
C:Users.awscredentials
location.When running the application in docker, credential file is not found in the container. Hence, SDK fallbacks to other ways to locate the AWS credentials.
Here, I have explained how does AWS SDK for .NET loads credentials.
Solution
Now, answering you question:
This should fix your issue.