Failed to retrieve credentials from EC2 Instance Metadata Service

In case if someone came here with no knowledge about configuring AWS from scratch. Just adding some details:

  • install AWS Toolkit (Extension for Visual Studio in my case: Extensions > Manage Extensions > "AWS Toolkit for Visual Studio 2017 and 2019") - https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/setup.html#install
  • In AWS Console create access key (and download as .csv file with secret key, for example) - https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey
  • Open View > AWS Explorer and add New Account Profile. Here you can import credentials from .csv

After that I could access AWS services locally


I figured out an answer to my question.

The issue can be resolved by creating an IAM user group and user with access to the SES service.

Then I edited my code to pass the AccessKeyId and SecretAccessKey.

    var client = new AmazonSimpleEmailServiceClient(awsAccessKeyId, awsSecretAccessKey, RegionEndpoint.USWest2);
    var response = new SendEmailResponse();

This is working. However to be more secure it's recommended that a Shared Credentials File be used.

Hope this helps someone else.

EDIT: In V2 of the AWS SES SDK you need to change AmazonSimpleEmailServiceClient to AmazonSimpleEmailServiceV2Client.

    var client = new AmazonSimpleEmailServiceV2Client(awsAccessKeyId, awsSecretAccessKey, RegionEndpoint.USWest2);
    var response = new SendEmailResponse();