0

I want to develop java application and deploy on EC2. As much as I understand you should use roles instead of access key and secret key.

Now suppose I launch an instance , with a S3 full access role attached to it , then how I will make a API call ?

Because for SDK it needs access key and secret key as follows :

AWSCredentials credentials = new BasicAWSCredentials("YourAccessKeyID", "YourSecretAccessKey");

AmazonS3 s3client = new AmazonS3Client(credentials);

I am not understanding how it will work ?

Piyush Patil
  • 14,512
  • 6
  • 35
  • 54
Shivkumar Mallesappa
  • 2,875
  • 7
  • 41
  • 68

1 Answers1

3

You are only looking at one of the possible ways to instantiate an SDK client object. To use the EC2 instance profile you would simply instantiate an AmazonS3Client object like this, without supplying credentials:

AmazonS3Clent s3client = new AmazonS3Client();

If credentials aren't specified, then the AWS SDK will look for credentials in environment variables, Java system properties, the default credentials file, and then the EC2 instance profile. This is documented here.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • Thanks for the response. Sir I have one more doubt.Is it possible for me to retrieve all the roles attached to the instance by using IAM getRole() without using credentials as you mentioned in your answer.Basically I want to get the roles attached with the Instance without providing accesskey and secret key. Is it necessary then to have role for IAM permissions attached to the instance. Or there any way to get the roles from the instance meta data. – Shivkumar Mallesappa Sep 05 '16 at 18:27
  • @ShivkumarMallesappa that's a completely separate question. 1: Why don't you just try it and see? 2: If you need help with it after you've tried, post it as a separate question here on StackOverflow. – Mark B Sep 05 '16 at 18:29
  • Thank you sir. I will definitely mark this answer as correct once I am done with all the trial and error.Hope you don't mind. – Shivkumar Mallesappa Sep 05 '16 at 18:31