Skip to main content

Bucket policy examples

Copy an example, replace the placeholders, and attach it as described in Creating bucket policies. Placeholders:

  • <bucket>: your bucket name
  • <domain_id> and <user_id>: the S3 user you're granting access to
  • IP ranges such as 203.0.113.0/24: your own addresses

A bucket can have only one policy. To combine examples, put their statements into one Statement list.

Public read-only access​

Use this when you serve files to anyone on the internet, such as website images or public downloads.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadOnlyAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket>/*"
}
]
}

Anyone with a file's URL can download it, but they can't list the bucket. Don't put anything private in a public bucket.

Public read access to one folder​

Use this when only part of a bucket should be public, for example public/ for downloads while the rest stays private.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadOneFolder",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket>/public/*"
}
]
}

Read access from one IP range​

Use this when files should be downloadable without a key, but only from your office or servers.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReadFromOfficeOnly",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket>/*",
"Condition": {
"IpAddress": { "aws:SourceIp": "203.0.113.0/24" }
}
}
]
}

Block all access from outside your network​

Use this when a bucket must only ever be reached from known IP ranges, even with valid keys.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyOutsideOurNetworks",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::<bucket>", "arn:aws:s3:::<bucket>/*"],
"Condition": {
"NotIpAddress": { "aws:SourceIp": ["203.0.113.0/24", "198.51.100.10/32"] }
}
}
]
}

This also applies to you as the owner. Include every address you work from, including the one you use for the web panel. If you lock yourself out, the owner can still delete the policy.

Let another S3 user upload​

Use this when another S3 user, such as a partner or a separate application user, needs to put files into your bucket.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowUserUpload",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::<bucket>/*"
}
]
}

Let a user list and read one folder​

Use this when a user should see and download files in one folder but nothing else in the bucket.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowListOneFolder",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<bucket>",
"Condition": {
"StringLike": { "s3:prefix": "reports/*" }
}
},
{
"Sid": "AllowReadOneFolder",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket>/reports/*"
}
]
}

Require TLS 1.2 or newer​

Use this when your security policy forbids old TLS versions. This example blocks uploads over TLS 1.0 and 1.1.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyOldTls",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": ["arn:aws:s3:::<bucket>", "arn:aws:s3:::<bucket>/*"],
"Condition": {
"NumericLessThan": { "s3:TlsVersion": 1.2 }
}
}
]
}

To cover downloads as well, change "Action" to "s3:*".

Prevent deletion of objects​

Use this when you want to stop accidental deletes by other users and applications.

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyObjectDeletion",
"Effect": "Deny",
"Principal": "*",
"Action": ["s3:DeleteObject", "s3:DeleteObjectVersion"],
"Resource": "arn:aws:s3:::<bucket>/*"
}
]
}

Both actions matter. On a versioned bucket, s3:DeleteObject only adds a delete marker, while s3:DeleteObjectVersion removes data permanently. To stop data being deleted by anyone, including the bucket owner, use Object Lock. A policy can always be removed by the owner.

Upload-only backup user from one IP range​

Use this when a backup server should be able to write new backups but not read, list or delete anything, and only from its own IP range. If the server is compromised, the attacker can't use its key to destroy your existing backups.

Create a separate S3 user for the backup server first (see Managing access keys), then attach this policy as the bucket owner:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BackupWriterPutOnlyFromOffice",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::<domain_id>:<user_id>" },
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::<bucket>/*",
"Condition": {
"IpAddress": { "aws:SourceIp": "203.0.113.0/24" }
}
}
]
}

This works for tools that only write, such as a script that runs aws s3 cp for each new dump. Many backup tools also need to list the bucket and read their own metadata. For those, see the backup target guide.

More examples​

Most examples in the Amazon S3 bucket policy documentation also work here, as long as they only use the supported actions and condition keys.

Was this page helpful?