I'm writing an aspnet core app which can be deployed to either azure or aws. The Microsoft libraries for accessing azure logging / configuration sources are well-behaved and fail silently if they're not in an appropriate environment. However the AWS SDK blows up with and exception Unable to get IAM security credentials from EC2 Instance Metadata Service.
if the providers are configured outside of AWS. Are there some environment variables I can look at to determine if my application is running in AWS so I can skip those?
Asked
Active
Viewed 1,544 times
2

JeffreyABecker
- 2,724
- 1
- 25
- 36
-
1How did you deploy? You cannot say merely Azure or AWS, as Azure has Azure App Services and raw VMs for example. Which service did you use? Make your question clear enough for others to answer. – Lex Li Feb 21 '20 at 21:19
-
I'd assert that the target environment is irrelevant -- the AWS SDK manages to do its thing transparently regardless of the environment. The the problem here is that the AWS SDK is failing if it doesn't find some combination of environmental factors. Maybe the better title is "How does the AWS SDK find its configuration sources"? – JeffreyABecker Feb 24 '20 at 17:50
-
Then you might do some quick search in its code base https://github.com/aws/aws-sdk-net – Lex Li Feb 24 '20 at 18:01
-
Have you seen the codebase? Its a mess. I spent 3 days digging through it and cant accurately understand what its looking for. – JeffreyABecker Feb 24 '20 at 20:22
1 Answers
2
All EC2 instances (and therefore all AWS hosting methods) have access to an instance meta-data http service running on a local-link address at http://169.254.169.254/latest/meta-data/. The best process I can come up with is to make a call to this service. If the call fails -- the process is not hosted on an EC2 instance.

JeffreyABecker
- 2,724
- 1
- 25
- 36