AWS - S3 - Creating a Bucket Policy - Error: Access Denied

0004

Trying to create an Amazon Web Services - S3 bucket policy, but when running the script I get the following error. Where exactly is my access being denied? Could this issue relate to how I set up my aws configur

Traceback (most recent call last):
  File "C:\Users\*****\githubb\aws\s3operations.py", line 40, in <module>
    print(create_bucket_policy())
  File "C:\Users\Patrick\githubb\aws\s3operations.py", line 36, in create_bucket_policy
    Policy=policy_string
  File "C:\Users\Patrick\Python36\lib\site-packages\botocore\client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\Users\Patrick\Python36\lib\site-packages\botocore\client.py", line 661, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occur

red (AccessDenied) when calling the PutBucketPolicy operation: Access Denied

The following is my script:

import boto3
import json

BUCKET_NAME ='patricksbucket'

def s3_client():
    s3 = boto3.client('s3')
    """:type : pyboto3.s3"""
    return s3

def create_bucket(bucket_name):
    return s3_client().create_bucket(
        Bucket=bucket_name,
        CreateBucketConfiguration={
            'LocationConstraint': 'us-east-2'
            }
        )

def create_bucket_policy():
    bucket_policy = {
        "Vesrion": "2012-10-17",
        "Statement":[
            {
            "Sid": "AddPerm",
            "Effect": "Allow",
            "Principal": "*",
            "Action":["s3:*"],
            "Resource":["arn:aws:s3:::patricksbucket/*"]
            }
        ]
    }
    policy_string = json.dumps(bucket_policy)

    return s3_client().put_bucket_policy(
        Bucket=BUCKET_NAME,
        Policy=policy_string
    )
if __name__ == '__main__':
    #print(create_bucket(BUCKET_NAME))
    print(create_bucket_policy())
jslipknot

It could happens because of several reasons although mainly related to your credentials or your policy. Anyway, you just follow the permission specifications that say how to grant everything with a wildcard as I see in your code

An example from Amazon Docs can shed a light

    "Action": "*"
    "Action": "s3:*"

The other reason, additional to the one above, is your credentials. For example, if you use AWS CLI

    $ aws configure
    AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
    AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    Default region name [None]: us-west-2
    Default output format [None]: json

Hope it helps (:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

AWS S3 Bucket policy editor access denied

Access denied when put bucket policy on aws s3 bucket with root user (= bucket owner)

Access Denied when creating S3 Bucket ACL & S3 Policy using Terraform

Access denied on AWS s3 bucket even with bucket and/or user policy

AWS S3 Bucket policy Access Denyed

AWS CloudFront access denied to S3 bucket

AWS S3 Bucket - Access Denied on Sub-Pages

Rails AssetSync and AWS s3 Bucket Access Denied

S3 Bucket Policy to allow S3 Access to Current Authenicated user in AWS Console?

AWS: Could not able to give s3 access via s3 bucket policy

Creating S3 bucket policy in serverless - An error occurred: BucketPolicy - Invalid policy syntax

Amazon s3 bucket policy access denied when hosting static webpage

access denied when I attempt to upload to s3 with a signed post could it be the bucket policy?

Access is denied even if IAM user is specified in S3 bucket policy

AWS S3 bucket policy with condition

AWS S3 Bucket Policy is not valid

AWS S3 Bucket Policy Whitelist

AWS S3 empty bucket policy

AWS S3 bucket policy for Get object, error in the policy generator Json code

s3 Bucket Policies Access Denied

AWS S3 Server side encryption Access denied error

AWS S3 custom error document for access denied

AWS S3 : access denied to object while "bucket block public access" is off

Error when creating S3 bucket policy - Value of property PolicyDocument must be an object

AWS Cloudfront - S3 with CloudFront Origin Access and Referer bucket policy

AWS S3 Bucket Policy: How to grant access to EC2 instance?

How to grant access only to the Root Account User for an S3 bucket with IAM Policy AWS?

AWS S3 Transfer Manager ${cognito-identity.amazonaws.com:sub} Policy Variable Access Denied

Spring Boot Amazon AWS S3 Bucket File Download - Access Denied

TOP Ranking

HotTag

Archive