Skip to main content

๐ŸŒ 03. S3 Bucket Policy Hands On

In this hands-on, weโ€™ll make an S3 bucket publicly accessible so that files (e.g., coffee.jpg) can be viewed via a public URL.


๐Ÿงฉ 01. Allow Public Accessโ€‹

  1. Go to your S3 bucket โ†’ Permissions tab.
  2. Under Block Public Access, click Edit.
  3. Untick all options that block public access.
  4. Confirm by clicking Save changes.

โš ๏ธ Only disable this if you intentionally want a public bucket (e.g., for static website hosting).


๐Ÿงฑ 02. Create a Bucket Policyโ€‹

  1. Scroll to Bucket Policy and click Edit Policy.

  2. Use the AWS Policy Generator:

    • Select Type: S3 Bucket Policy
    • Effect: Allow
    • Principal: *
    • Action: s3:GetObject
    • ARN: arn:aws:s3:::your-bucket-name/*
  3. Generate and copy the JSON.


๐Ÿงพ 03. Example Policyโ€‹

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadAccess",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}
  1. Paste this JSON into the Bucket Policy Editor and Save changes.
  2. Ensure there are no extra spaces or syntax errors.
IAM Roles Example
IAM Roles Example

๐ŸŒ 04. Verify Public Accessโ€‹

  1. Go to Objects โ†’ select your file (e.g., coffee.jpg).
  2. Copy the Object URL.
  3. Open it in a browser.
    โœ… If configured correctly, the image should display publicly.
IAM Roles Example

๐Ÿง  Summaryโ€‹

StepActionPurpose
1Disable Block Public AccessAllow public policies to work
2Create Policy with Principal: *Grant global read access
3Apply PolicyMake bucket objects public
4Test URLConfirm accessibility

๐Ÿ“Œ Result: Your coffee.jpg file (and other objects) are now publicly viewable via a direct S3 URL.