I want to upload a file to S3 without using my access and secret key from AWS
server. AWS keys should be taken as default. However running the below command in server I can access it without providing any access and secret keys.
aws s3 cp somefile.txt s3://somebucket/
From java code its not accessible since it was unable to load credentials. Below is my code.
AmazonS3 s3client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain());
As per documentation AWS credentials provider chain that looks for credentials in this order :
Check you have specify valid credentials in any of above.
Ref : http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
You can use the below Java code to get the
s3client
instance when you are trying to connect to S3 bucket from EC2 instance.This is the recommended way as the application doesn't require to maintain the access keys in property files.
Sample policy for IAM role:-