EchoVibe

put-bucket-policy AWS CLI 2.7.12 Command Reference

Description

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

See ‘aws help’ for descriptions of global parameters.

Synopsis

 put-bucket-policy --bucket <value> [--content-md5 <value>] [--checksum-algorithm <value>] [--confirm-remove-self-bucket-access | --no-confirm-remove-self-bucket-access] --policy <value> [--expected-bucket-owner <value>] [--cli-input-json | --cli-input-yaml] [--generate-cli-skeleton <value>] 

Options

--bucket (string)

The name of the bucket.

--content-md5 (string)

The MD5 hash of the request body.

For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.

--checksum-algorithm (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.

Possible values:

  • CRC32

  • CRC32C

  • SHA1

  • SHA256

--confirm-remove-self-bucket-access | --no-confirm-remove-self-bucket-access (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.

--expected-bucket-owner (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).

--cli-input-json | --cli-input-yaml (string) Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. Similarly, if provided yaml-input it will print a sample input YAML that can be used with --cli-input-yaml. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

See ‘aws help’ for descriptions of global parameters.

Examples

This example allows all users to retrieve any object in MyBucket except those in the MySecretFolder. It also grants put and delete permission to the root user of the AWS account 1234-5678-9012:

aws s3api put-bucket-policy --bucket MyBucket --policy file://policy.json policy.json: { "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::MyBucket/*" }, { "Effect": "Deny", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::MyBucket/MySecretFolder/*" }, { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:root" }, "Action": [ "s3:DeleteObject", "s3:PutObject" ], "Resource": "arn:aws:s3:::MyBucket/*" } ] } 

Output

None

ncG1vNJzZmiZp6iwrbWNmqSasp%2Bjrri%2FjZympmemZ3ylu8KupJ6mpJbBqrvNaJipoV9ne3h6kGtmq52Wmr%2BmusKeZqxrkaW2cLzUrWSbrZOgsrV5z6ijopupY7W1ucs%3D

Merlyn Hunt

Update: 2024-05-09