Shivkumar Mallesappa
Shivkumar Mallesappa

Reputation: 3077

How to make API request using roles

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 ?

Upvotes: 1

Views: 336

Answers (1)

Mark B
Mark B

Reputation: 200501

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.

Upvotes: 3

Related Questions