1

Below code creates AWS Credentials where access and secret keys are explicitly supplied.

AWSCredentials credentials = new BasicAWSCredentials(
  "<AWS accesskey>", 
  "<AWS secretkey>"
);

But the issue with this approach is in production I can not use it. So what will be an equivalent java code that will obtain credential automatically from the aws credentials chain and create a credential object or some EC2 client.

samshers
  • 1
  • 6
  • 37
  • 84

1 Answers1

2

There are several alternatives you can use to store and recover your credentials in production. You should check the official documentation by AWS about 'Using the Default Credential Provider Chain'. Basically, you can use any of these alternatives:

  • Environment variables.
  • Java system properties.
  • The default credential profiles file.
  • Amazon ECS container credentials.
  • Instance profile credentials.

Depending on which one you choose it would use a different code. You have guidelines on how to use them in the above link.

Drubio
  • 1,157
  • 3
  • 13
  • 30