Search code examples
amazon-web-servicesamazon-s3amazon-ec2bucket

AWS S3 List Objects Access Denied On EC2


Iam new to AWS and now Iam facing the access denied problem when excuted

aws s3api list-objects --bucket BUCKET_NAME

Here are what I configured:

  • IAM role: attach AmazonS3FullAccess policy
  • EC2: attach above IAM role
  • Bucket:
    • Block all public access: OFF
    • Policy: allow all action
    • ACL: OFF
    • Other setting: default

IAM Role policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:*",
                "s3-object-lambda:*"
            ],
            "Resource": "*"
        }
    ]
}

Bucket Policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowAllActionsForUsersWhoCanList",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::BUCKET_NAME/*",
                "arn:aws:s3:::BUCKET_NAME"
            ]
        }
    ]
}

enter image description here


Solution

  • After trying numerous solutions, I finally realized that the problem was with my VPC endpoint to S3. There was a policy limiting access to resources. I want to express special thanks to John Rotenstein, who provided me with a lot of adviceenter image description here