How to get an S3 Bucket's URL

avatar
Borislav Hadzhiev

Last updated: Feb 26, 2024
3 min

banner

# 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

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 this: 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" subheading.

# Get an S3 Object's URL using the AWS console

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

# Get an S3 Object's URL based on the bucket's URL

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, the URL of an index.html file located at the root of the bucket would look similar to the following:

  • 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

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.