Tung Nguyen
Tung Nguyen

Reputation: 46

How to fix ClientError: An error occurred (AccessDenied) when calling the CreateBucket operation: Access Denied when calling create_bucket

I tried using boto3 to create a bucket in s3 but received ClientError: An error occurred (AccessDenied) when calling the CreateBucket operation: Access Denied.

I have set up my aws cli credentials through aws configure. Here's my permissions summary:

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

This is my code:

s3.create_bucket(Bucket=bucket_name, ACL='public-read',
                  CreateBucketConfiguration={
                  'LocationConstraint': 'us-west-2'
},)

I want to be able to create a bucket without getting Access denied

Upvotes: 2

Views: 9833

Answers (1)

Alon Gweta
Alon Gweta

Reputation: 427

I encountered the same issue while running on EC2 instance and its seems that for using credentials for Amazon EC2 you need to follow these instructions https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-metadata.html

  • Make sure you delete the credentials you set with aws cli and then edit your ~/.aws/config as the instructions mention

Upvotes: 0

Related Questions