skip to Main Content

In a Spring Boot project, I try to get list of buckets. I don’t have a bucket yet. Error is as follows:

Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied

I created the access & secret keys an hour ago. I tried to delete and re-create bu no chance. Is there anything missing?

AWSCredentials credentials = new BasicAWSCredentials(
    "myaccesskey", 
    "mysecretkey"
    );

    AmazonS3 s3client = AmazonS3ClientBuilder
    .standard()
    .withCredentials(new AWSStaticCredentialsProvider(credentials))
    .withRegion(Regions.US_EAST_1)
    .build();

    try{
        List<Bucket> buckets = s3client.listBuckets();
        
        for(Bucket bucket : buckets) {
            response += bucket.getName();
        }
    } catch (Exception exception) {
        System.out.print(exception);
    }    

2

Answers


  1. Chosen as BEST ANSWER

    I solved the problem by adding permission AmazonS3FullAccess on the Permissions Policies panel and restarted spring boot and all works well.


  2. Following the official guide to explicitly specifying credentials in Java, you don’t need to specify the region while instantiate the credentials.

    Check also the permissions on the user for which you created the keypair, the ListBuckets API needs at least the s3:ListAllMyBuckets permission, as stated here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search