aws-sdk-net: How to troubleshoot "Unable to get IAM security credentials from EC2 Instance Metadata Service."?
The Question
Why do I get Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service. in my development environment? Is the issue that my development environment is an Amazon Workspace and not an EC2 Instance, and thus does not have EC2 Instance Metadata? How do I run the sample code in Making requests using IAM user temporary credentials - AWS SDK for .NET on a non-EC2 instance like an Amazon Workspace machine (my development environment)?
My end goal is to be able to:
- Not use access key/secret key, but instead resolve credentials via Delegating access across AWS accounts using IAM roles.
- However, when I run the code I found Making requests using IAM user temporary credentials - AWS SDK for .NET, I get the aforementioned exception
I read the following documentation:
- https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/aws-sdk-net-v3-dg.pdf - I read Page 5, which discusses creating a
Dotnet-Tutorial-User. Note: This is a bit weird, since it seems like the tutorial is asking me to go backwards to using access key and secret key. - Realizing the tutorial seemed to be advocating bad practices, I googled until I somehow landed on Making requests using IAM user temporary credentials - AWS SDK for .NET - this seemed like exactly what I needed, but when I added this logic to my existing program, I got the above error
- I also, of course, read Delegating access across AWS accounts using IAM roles, which got me started on this whole “let’s get rid of insecure access keys/secret keys that can be stolen” rabbit trail
- Separately, my understanding is that the AWS Extension for Visual Studio can be used to generate access, but that the extension just creates user profiles, which doesn’t really get around the fact that then these credentials are stored in raw text files on my machine.
Environment
- SDK Version: 3.5.0.9
- Package Version:
<PackageReference Include="AWSSDK.SecurityToken" Version="3.5.0.9" />
<PackageReference Include="AWSSDK.S3" Version="3.5.0.9" />
- OS Info: Windows Server 2016 Datacenter Edition (Amazon Workspace largest instance size)
- Build Environment Visual Studio 2019 16.6.5
- Targeted .NET Platform: netstandard2.1 library, called from netcoreapp3.1 executable context
This is a ❓ general question
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 25 (7 by maintainers)
i have a same problem when running the application in docker container and getting assume role.
The root cause is missing AWS credentials.So we need to have a AWS profile or add these 2 environment variables:
Another sharing is i wanting to mock the amazon request with the mock server, so all need to do is set any key and secret into above environment variables.
hmm, it took around 4h to research, read many documents without result, but finally i can solved it by compare between run application with IDE and docker container lol
If you go to Amazon Workspaces page, there is a Contact Us link at the bottom of the page. It would open a case with support.
Thanks, Ashish
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/dotnet/example_code_legacy/STS appears to have some examples.
Thanks, Ashish
One last follow-up, in case someone finds this via Google. I found https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html which explains the guidance on how to create a provider chain of responsibility pattern in the section titled Credential and Profile Resolution
Good grief, Amazon has a LOT of documentation around IAM, creds, and profiles
@ashishdhingra Thank you so much - have a great weekend!
I have added feature-request label to this issue.
Thanks, Ashish
So… for most people, it’s considered normal to not be able to debug locally their temporary access credentials? Is that really how people do this?
It seems like a good feature request to be able to have temporary access credentials available to Amazon Workspace machines with STS privileges to things like AmazonS3FullAccess. How do I request that?