S3.Client.
put_bucket_policy
(**kwargs)¶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.
Warning
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',
ChecksumAlgorithm='CRC32'|'CRC32C'|'SHA1'|'SHA256',
ConfirmRemoveSelfBucketAccess=True|False,
Policy='string',
ExpectedBucketOwner='string'
)
[REQUIRED]
The name of the bucket.
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.
[REQUIRED]
The bucket policy as a JSON document.
403 Forbidden
(access denied).None
Examples
The following example sets a permission policy on a bucket.
response = client.put_bucket_policy(
Bucket='examplebucket',
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/*" ] } ]}',
)
print(response)
Expected Output:
{
'ResponseMetadata': {
'...': '...',
},
}