AWS S3 URL Styles
Category: Cloud Computing
Written on
S3 endpoints
Before describing S3 bucket URL schemes, one thing that causes a lot of the confusion needs to be clarified. And that thing is S3 endpoint.
S3 endpoint is a region-specific URL that is used in both S3 URL styles (more on styles below). Follow the link to see the list of all S3 endpoints.
Most of the endpoints follow this pattern (with region names being eu-west-1, us-west-2, etc):
s3-REGION.amazonaws.com
Examples:
s3-eu-west-1.amazonaws.com
s3-us-west-2.amazonaws.com
But there are a few quirks to the general naming scheme.
The first two outstanding endpoints that do not follow the above pattern are those of the us-east-1 (N. Virginia, also called US Standard) region. For that region endpoints are (they are synonyms and both point to the same place):
s3.amazonaws.com
s3-external-1.amazonaws.com
The other quirk is that eu-central-1 (Frankfurt) and ap-northeast-2 (Seoul) regions both have one endpoint that follows the general pattern and one alias endpoint that differs from the general scheme in one symbol (first dash is replaced by dot):
s3-eu-central-1.amazonaws.com
s3.eu-central-1.amazonaws.com
s3-ap-northeast-2.amazonaws.com
s3.ap-northeast-2.amazonaws.com
S3 bucket URL schemes
Now, after comprehending S3 endpoints, understanding of S3 bucket URL styles should be a breeze. According to S3 Developer Guide (PDF, p.57), S3 supports both virtual-hosted and path URL styles for bucket access.
Path style URL
In path style URL bucket name is appended to the domain name and is a part of URL path:
http://s3endpoint/BUCKET
For example, if your store photo.jpg into images bucket residing in the us-west-2 region, you could access that file with
http://s3-us-west-2.amazonaws.com/images/photo.jpg
To access the file from bucket located in eu-central-1 region, you could use either of the following URLs:
http://s3-eu-central-1.amazonaws.com/images/photo.jpg
http://s3.eu-central-1.amazonaws.com/images/photo.jpg
And to access the file from bucket residing in us-east-1 region, you would have to use either of the following two URLs:
http://s3.amazonaws.com/images/photo.jpg
http://s3-external-1.amazonaws.com/images/photo.jpg
Virtual-hosted style URL
In virtual-hosted style URL the bucket name becomes a subdomain:
http://BUCKET.s3endpoint
To access photo.jpg file stored in images bucket that resides in the us-west-2 region, you would use the following URL:
http://images.s3-us-west-2.amazonaws.com/photo.jpg
To access the file from bucket located in eu-central-1 region, you could use either of the following URLs:
http://images.s3-eu-central-1.amazonaws.com/photo.jpg
http://images.s3.eu-central-1.amazonaws.com/photo.jpg
And to access the file from bucket registered in us-east-1 region, you would have to use either of the following two URLs:
http://images.s3.amazonaws.com/photo.jpg
http://images.s3-external-1.amazonaws.com/photo.jpg
Note, however, one important thing. With virtual-hosted style you can additionally use s3.amazonaws.com endpoint for any bucket residing in ANY region. Because bucket name is part of the domain name, AWS backend has sufficient information to correctly resolve or redirect (with 307 Temporary Redirect HTTP response code) your request to the region where the bucket resides. For example the following pairs of requests are equivalent:
http://images.s3-us-west-2.amazonaws.com/photo.jpg
http://images.s3.amazonaws.com/photo.jpg
http://gods.s3.eu-central-1.amazonaws.com/odin.jpg
http://gods.s3.amazonaws.com/odin.jpg
This last feature is very convenient in my opinion.
Static Website Hosting Endpoints
Finally, note that if you use S3's Static Website Hosting feature you will need to use Website Endpoints.
There are two general forms of S3 website endpoint:
http://BUCKET.s3-website-region.amazonaws.com
http://BUCKET.s3-website.region.amazonaws.com
Most of the regions follow the first form, while eu-central-1 and ap-northeast-2 follow the second. Follow the link for the list of all S3 website endpoints.