Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing AWS credentials separately and accessing those in java code

I am using java to upload and download files from s3. My problem is that I can't check in the code along with the secret and access key to public but the code has to checked in to a public environment. How can I manage my credentials separately and access only its references in my code?

the code I used is

String awsAccessKey = "YOUR_AWS_ACCESS_KEY";
String awsSecretKey = "YOUR_AWS_SECRET_KEY";
AWSCredentials awsCredentials = 
    new AWSCredentials(awsAccessKey, awsSecretKey);

I want the credentials manager to be platform independent.

like image 899
Shyamala Selvaganapathy Avatar asked Dec 30 '13 07:12

Shyamala Selvaganapathy


1 Answers

You could implement an AWSCredentialsProvider, which is an interface for supplying credentials to SDK clients. For example the DefaultAWSCredentialsProviderChain is an implementation which looks in multiple places for credentials (the environment, a properties file, and EC2 instance profile).

You can check out the implementation of several credentials providers in the AWS SDK for Java Github repo.

like image 178
Jim Flanagan Avatar answered Sep 20 '22 13:09

Jim Flanagan