Applies an Amazon S3 bucket policy to an Amazon S3 bucket. If you are using an identity other than the root user of the Amazon Web Services account that owns the bucket, the calling identity must have the PutBucketPolicy permissions on the specified bucket and belong to the bucket owner's account in order to use this operation.

If you don't have PutBucketPolicy permissions, Amazon S3 returns a 403 Access Denied error. If you have the correct permissions, but you're not using an identity that belongs to the bucket owner's account, Amazon S3 returns a 405 Method Not Allowed error.


As a security precaution, the root user of the Amazon Web Services account that owns a bucket can always use this operation, even if the policy explicitly denies the root user the ability to perform this action.

For more information, see Bucket policy examples.

The following operations are related to PutBucketPolicy :

See also: AWS API Documentation

Request Syntax

response = client.put_bucket_policy(
  • Bucket (string) --


    The name of the bucket.

  • ChecksumAlgorithm (string) --

    Indicates the algorithm used to create the checksum for the object when using the SDK. This header will not provide any additional functionality if not using the SDK. When sending this header, there must be a corresponding x-amz-checksum or x-amz-trailer header sent. Otherwise, Amazon S3 fails the request with the HTTP status code 400 Bad Request . For more information, see Checking object integrity in the Amazon S3 User Guide .

    If you provide an individual checksum, Amazon S3 ignores any provided ChecksumAlgorithm parameter.

  • ConfirmRemoveSelfBucketAccess (boolean) -- Set this parameter to true to confirm that you want to remove your permissions to change this bucket policy in the future.
  • Policy (string) --


    The bucket policy as a JSON document.

  • ExpectedBucketOwner (string) -- The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with the HTTP status code 403 Forbidden (access denied).



The following example sets a permission policy on a bucket.

response = client.put_bucket_policy(
    Policy='{"Version": "2012-10-17", "Statement": [{ "Sid": "id-1","Effect": "Allow","Principal": {"AWS": "arn:aws:iam::123456789012:root"}, "Action": [ "s3:PutObject","s3:PutObjectAcl"], "Resource": ["arn:aws:s3:::acl3/*" ] } ]}',


Expected Output:

    'ResponseMetadata': {
        '...': '...',