AwsCredentialsProvier using environment variables

751 views Asked by At

I am trying to create a new AmazonS3Client by passing in a new AmazonCredentialsProvider. Just a simple java function. Online documentation states that if you have environment variables for AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY, the AmazonCredentialsProvider will look for those to get credentials. My current implementation follows as such

AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();
AWSCredentials credentials = provider.getCredentials();
credentials.getAWSSecretKey();
credentials.getAWSSecretKey();

return new AmazonS3Client(credentials, clientConfiguration)

It is throwing me the error that it Failed to get S3 Credentials. Just as a safe measure, I have also added the credentials to my ./aws/credentials file. Does anyone know a solution as to safely get credentials from environment variables?

1

There are 1 answers

0
am233dmg On

If you use Intelij Idea, you able to put environment variables via:
From the main menu, select Run | Edit Configurations, Environment Variables(so you can add you variables).