2

I’m running Visual Studio 2019 with the AWS Explorer installed with a profile on an Amazon Workspace. Until today, I’ve been able to debug Lambda projects locally using the AWS .NET Core 3.1 Mock Lambda Test Tool. Today, I needed to do some CLI work and noticed the CLI wasn’t installed so I installed the latest version. After installing, my code fails when trying to access any AWS service with the error:

Unable to get IAM security credentials from EC2 Instance Metadata Service.

I’ve verified that my credentials file is correct at /.aws/credential and that AWS Explorer is picking that up and I can browse services and objects in the AWS Explorer.

I’ve deleted the credential file and recreated using aws configure. No change.

I’ve deleted the credential file and recreated using the AWS Explorer. No change.

I’ve uninstalled and reinstalled the AWS CLI and AWS Explorer and recreated the profile. No Change.

I’ve set windows environment variables for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. This works.

Obviously, I can hard code my access key and secret into my client when I create it and that works.

The question is, why won’t my code pick up the credentials from my /.aws/credentials file? Anything else I can try?

Jay
  • 624
  • 1
  • 6
  • 19
  • [Does it help?](https://stackoverflow.com/a/62061272/16764901) – Jiale Xue - MSFT Nov 08 '21 at 06:27
  • No, I created credentials through the AWS toolkit as well as the command line multiple times. I've deleted the credentials from the disk and rebooted and done whatever else I can think to flush it. For whatever reason, VS won't read the credentials. – Jay Nov 08 '21 at 22:05

1 Answers1

0

You need to confirm what "the default" location for your credentials file is that AWS SDK is using. This is what AWS SDK considers the default base directory:

    var baseDirectory = Environment.GetEnvironmentVariable("HOME");

    if (string.IsNullOrEmpty(baseDirectory))
            baseDirectory = Environment.GetEnvironmentVariable("USERPROFILE");

Just dump the runtime values and either place a copy of your .aws folder there or use the app setting

"AWS": {
    "AWSProfilesLocation": "C:\\Users\\YOUR_USER_NAME\\.aws\\credentials",
    ....

to point the SDK to the credentials file.

G. Stoynev
  • 7,389
  • 6
  • 38
  • 49