Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing application locally that uses IAM Role

I have a Java application which does adds files in S3. This application is running in a EC2 instance.

We are using IAM role. So we have attached the required IAM role to this EC2 instance.

Everything works perfect there.

But we would like to test the application locally in my laptop as well. It's hard to upload the application everytime to EC2 whenever I need to test it.

How can we switch dynamically without changing the code, so that I can test it my laptop (with accesskey and secretKey) as well as use IAM role in EC2?

like image 827
sag Avatar asked Apr 12 '16 08:04

sag


Video Answer


1 Answers

The AWS SDK uses a Credentials Provider Chain to locate credentials. The order differs by language, but generally it checks:

  • Environment Variables
  • Local configuration file
  • EC2 instance metadata

Therefore, if you want to run the application locally, you can either provide a credentials file or set credentials in Environment Variables. The code will automatically locate the credentials, just like it does on an EC2 instance.

References:

  • Providing AWS Credentials in the AWS SDK for Java
  • .Net Configuring AWS Credentials
  • PHP credentials provider chain
  • (and similar for other language SDKs)
like image 175
John Rotenstein Avatar answered Nov 02 '22 17:11

John Rotenstein