In this post, we explore the differences between the Path-style and Virtual-Host-style hosting on Amazon S3.

What is Path-Style hosting

Path-style hosting is a way in which you access your S3 bucket objects. In this format, the bucket name is included as part of the path within the URL, followed by the object key. The structure of the URL is:

https://s3.amazonaws.com/your-bucket-name/object-key

For example, I have a bucket called fb-test-bucket, and an object named index.html. You can access the object using the following URL:

https://s3.amazonaws.com/fb-test-bucket/index.html

Virtual-Host-Style hosting

Virtual-host-style hosting is another way in which you access your S3 bucket objects. In this format, the bucket name is included as part of the domain name within the URL, followed by the object key. The structure of the URL is:

https://your-bucket-name.s3.amazonaws.com/object-key

Using the same example as above, the URL would be:

https://fb-test-bucket.s3.amazonaws.com/index.html

Advantages and Disadvantages

Path-Style hosting was the default method for accessing S3 buckets but it was almost removed for new buckets in 2020. After some backlash, Amazon decided to keep it, but it is still recommended to use Virtual-Host-Style hosting.

The main advantage of Virtual-Host-Style hosting is that it is easier for AWS to secure. Managing a single, global domain name with the tremendous amount of traffic that S3 receives creates many engineering challenges.

The main disadvantage of Virtual-Host-Style hosting is that it is not compatible with some older clients and SDKs.

Conclusion

In all scenarios and for all clients, Virtual-Host-Style hosting is the recommended way to access your S3 buckets. If you are using an older client or SDK, you can use Path-Style hosting, but it is recommended to upgrade to the latest version as path-style hosting will eventually be deprecated.