Skip to main content

Creating bucket policies

Attach a policy to a bucket when you need to open it up (for example, public downloads or access for another S3 user) or lock it down (for example, only from your office IP range). If you're new to policies, read Bucket policies first, and start from one of the examples.

Before you start: create a bucket. Only the bucket owner can attach a policy.

Good practice​

  • Grant the smallest set of actions that does the job.
  • Avoid "Principal": "*" unless you really mean everyone, including anonymous users.
  • Add conditions, such as aws:SourceIp or s3:TlsVersion, to narrow access further.
  • Keep a copy of each policy in version control, and review policies from time to time.

In the web panel​

  1. Go to S3 > Buckets and click the line with the bucket.
  2. In the right pane, click Manage bucket policy.
  3. Either upload a JSON file with your policy, or build it in Policy builder:
    1. Click Add to add a statement.

    2. Enter a Sid (statement ID). Letters and numbers only, no spaces.

    3. Choose Allow or Deny.

    4. Select the S3 actions.

    5. Choose the resources: All objects in the bucket, or Select prefix or object and pick the folders or files with the folder icon.

      Choosing resources in the policy builder

    6. Choose the principals: All S3 users, or Specify S3 users or domains and enter each one as arn:aws:iam::<domain_id>:<user_id>.

      Choosing principals in the policy builder

    7. Optionally, under Conditions, click Add, choose a condition key and operator, and enter the value.

      Adding a condition in the policy builder

    8. Click Add to save the statement. Repeat for more statements.

  4. Check the result in JSON view. Click Download file to keep a copy.
  5. Click Save.

The active policy is shown on the bucket's Bucket policy tab.

With aws-cli​

Save the policy as policy.json, then attach it:

cd ~
aws s3api put-bucket-policy --bucket <bucket> --policy file://policy.json --profile bamboozle

Check what's attached:

cd ~
aws s3api get-bucket-policy --bucket <bucket> --query Policy --output text --profile bamboozle

put-bucket-policy replaces any existing policy, so always upload the complete policy, not just the new statement.

Policy changes take a short time to apply everywhere. Wait a minute before testing.

Was this page helpful?