Amazon S3: Bucket Policy Hands-On | A Step-by-Step Guide

A step-by-step instructions for creating a bucket policy in Amazon S3 to allow public access to files

Amazon S3: Bucket Policy Hands-On | A Step-by-Step Guide

Here's a step-by-step guide for creating a bucket policy in Amazon S3 to allow public access to files:

Step 1: Navigate to Amazon S3 console

  1. Open your web browser and go to the AWS Management Console at https://console.aws.amazon.com/.

  2. Sign in to your AWS account using your credentials.

  3. Once logged in, locate and click on "S3" under the "Storage" category. This will open the Amazon S3 console.

Step 2: Create S3 Bucket

Ensure you have created your S3 bucket. If not, follow the steps outlined in the "AWS S3 Console Hands-On | A Step-by-Step Guide" tutorial available at: https://partnerpens.hashnode.dev/aws-s3-console-hands-on-a-step-by-step-guide

Step 3: Navigate to Bucket Settings

  1. In the S3 console, you'll see a list of your buckets. Click on the name of the bucket you want to apply the policy to. If you have many buckets, you may need to scroll or use the search bar to find the desired bucket.

  2. Select the bucket you want to apply the policy to.

  3. Click on the "Permissions" tab.

Step 4: Allow Public Access

  1. Under the "Public access settings for this bucket" section, click on "Edit".

  2. Untick the option that restricts public access to the bucket.

  3. Confirm the change by clicking "Save".

    Note: This action allows public access to the bucket, so use it with caution, ensuring it's appropriate for your use case.

    1. To confirm the settings, enter confirm in the field. and click confirm button

Step 5: Create Bucket Policy

  1. Scroll down to the "Bucket policy" section.

  2. Since there's no policy currently, click on "Edit bucket policy".

  3. You can explore example policies provided in the documentation, but for this guide, we'll use the Policy Generator.

Step 6: Use Policy Generator

  1. Click on "Policy Generator" to open the AWS Policy Generator.

  2. Select the policy type as "S3 Bucket Policy".

  3. For the Principal, enter "*", indicating access for anyone.

  4. Choose the action "GetObject" to allow reading objects from the bucket.

  5. Specify the Amazon Resource Name (ARN) as the bucket name followed by "/" to apply to all objects within the bucket. Example ARN: arn:aws:s3:::your-bucket-name/

  6. Generate the policy.

Step 7: Apply Policy

  1. Copy the generated policy from the Policy Generator.

  2. Paste the policy into the bucket policy editor in the S3 console.

  3. Save the changes.

Step 8: Verify Public Access

  1. Confirm that the access is set to public under the "Permissions" tab.

  2. Copy the public URL of an object inside the bucket

  3. Paste the public URL of an object in the bucket in browser to ensure it's accessible from anywhere on the internet. Example: https://s3.amazonaws.com/your-bucket-name/your-file.jpg

Conclusion

  1. Your bucket is now publicly accessible, and any files uploaded to it will be accessible using their public URLs.

  2. Ensure that this level of access aligns with your security requirements and use case.

That concludes the process of creating a bucket policy to allow public access to files stored in Amazon S3.