When you work with AWS S3, control is everything. A single misconfigured policy can open doors you never meant to unlock. That’s why read-only roles exist — to give secure, controlled access without risking accidental changes or deletions. If you know how to set them up with AWS CLI, you can grant the exact level of access needed and nothing more.
Why Use AWS S3 Read-Only Roles
Read-only roles keep your buckets safe while still making them useful. They let a user or service read objects, list bucket contents, and check basic metadata. They block all forms of write or delete actions. This is critical for log archives, compliance snapshots, backups, and datasets that must remain untouched.
Creating a Read-Only IAM Policy
First, define the IAM policy that allows s3:GetObject and s3:ListBucket. Save this JSON as s3-readonly-policy.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::my-bucket-name",
"arn:aws:s3:::my-bucket-name/*"
]
}
]
}
Create the Policy with AWS CLI
aws iam create-policy \
--policy-name S3ReadOnlyPolicy \
--policy-document file://s3-readonly-policy.json
Attach the Policy to a New Role
Create a trust policy for the role. Save it as trust-policy.json: