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

I want the credentials manager to be platform independent.


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.

Leave a Reply