Reputation: 1026
New to AWS S3, trying to integrate AWS Java SDK for S3 storage. Granted permission to to my user as follows
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Read Access",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::9123...123:root"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::go_bucket/*"
}
]
}
Still in Java code getting
Received error response: com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 6DRTT
Java code
final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build();
try {
S3Object o = s3.getObject(bucket_name, key_name);
S3ObjectInputStream s3is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream(new File(key_name));
byte[] read_buf = new byte[1024];
int read_len = 0;
while ((read_len = s3is.read(read_buf)) > 0) {
fos.write(read_buf, 0, read_len);
}
s3is.close();
fos.close();
}
But, when I am using "Principal": "*" it is working
Upvotes: 0
Views: 5305
Reputation: 1026
AWS SDK is not reading credentials from C:\Users\myuser\.aws\credentials
in Windows
As of now, below has solved the problem
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials("aws_access_key_id",
"aws_secret_access_key");
final AmazonS3 s3 = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.withRegion("us-east-1")
.build();
Upvotes: 1