How to get an S3 Bucket's URL

avatar

Borislav Hadzhiev

Wed Sep 22 20212 min read

Table of Contents #

  1. Get an S3 Bucket's URL
  2. Get an S3 Object's URL
  3. Solve 403 Forbidden Error when Accessing S3 Bucket

Get an S3 Bucket's URL #

In order to get an S3 bucket's URL:

  1. Open the AWS S3 console and click on your bucket's name
  2. Click on the Properties tab
  3. Scroll to the bottom and find the Static Website hosting section
  4. Copy the bucket's url, it will look something like - http://your-bucket.s3-website-us-east-1.amazonaws.com

get s3 bucket url

If opening the bucket URL gives you a "403 Forbidden" error, scroll down to the "Solve 403 Forbidden Error" section.

Get an S3 Object's URL #

In order to get the URL of an S3 Object via the AWS Console:

  1. Navigate to the AWS S3 console and click on your bucket's name
  2. Use the search input to find the object if necessary
  3. Click on the checkbox next to the object's name
  4. Click on the Copy URL button

get s3 object url

In order to get the URL of an S3 Object, based on the bucket's URL:

  1. Get the S3 Bucket's endpoint URL
  2. Append the path of the S3 object to the bucket's url

For example to get the index.html file, located at the root of the bucket it would look similar to: http://your-bucket.s3-website-us-east-1.amazonaws.com/index.html

To get the URL of a file located in the /images "directory", e.g. with a path /images/house.png you would have to append the whole path to the bucket url - http://your-bucket.s3-website-us-east-1.amazonaws.com/images/house.png.

Solve 403 Forbidden Error when Accessing S3 Bucket #

If you get the "403 Forbidden Error" when trying to access an S3 Bucket's endpoint, you have to grant public read access to your S3 bucket.

To grant public read access to your S3 bucket:

  1. Click on your bucket's name in the S3 console
  2. Click on the Permissions tab
  3. Find the Block public access (bucket settings) section, click on the Edit button, uncheck the checkboxes and Save the changes

uncheck checkboxes

  1. In the Permissions tab, navigate to the Bucket policy section and click on the Edit button. In the textarea paste the following bucket policy to grant public read access to your s3 bucket.
Replace the YOUR_BUCKET_NAME placeholder with your bucket's name.
bucket-policy-public-read
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject" ], "Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*" } ] }

Once you save the bucket policy, your bucket will have public read access enabled and the "403 Forbidden" error will be resolved.

Your bucket will be marked as publicly accessible, but the bucket policy only enables S3 read access.

bucket publicly accessible

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee