AWS S3 Java: doesObjectExist results in 403: FORBIDDEN

后端 未结 4 1641
余生分开走
余生分开走 2021-01-07 09:09

I\'m having trouble with my Java program using the AWS SDK to interact with an S3 bucket.

This is the code I use to create an S3 client:

public S3Sto         


        
相关标签:
4条回答
  • 2021-01-07 09:27

    I really look like an IAM policy issue. What is your user's policies on your local machine vs what is your IAM role with which policy(ies)? For your EC2 instance, when you create it, create a role with "AmazonS3FullAccess" policy, if it solves the problem you'll remove the useless rights.

    0 讨论(0)
  • 2021-01-07 09:30

    You need an action "ListBucket" for your bucket but not for the file in your bucket like: { "Action": [ "s3:ListBucket" ], "Resource": "arn:aws:s3:::bucketName", "Effect": "Allow" }

    0 讨论(0)
  • 2021-01-07 09:32

    Your credentials may be correct, but you will still get FORBIDDEN if you do not set the correct IAM polices. To check for objects in s3 you need the following:

    {
        "Version":"2012-10-17",
        "Statement":[
            {
                "Effect":"Allow",
                "Action":[
                "s3:ListBucket"
                ],
                "Resource":["arn:aws:s3:::examplebucket/*"]
            },
            {
                "Effect":"Allow",
                "Action":[
                "s3:GetObject"
                ],
              "Resource":["arn:aws:s3:::examplebucket/*"]
            }
        ]
    }
    
    0 讨论(0)
  • 2021-01-07 09:38

    Make sure the date time is set correctly on the machine you are making the request from, otherwise you will get a 403.

    0 讨论(0)
提交回复
热议问题