AWS Certified Developer - Associate
Storage
S3 Static Website Hosting
In this lesson, we explore how to use Amazon S3 for static website hosting. By uploading your website files into an S3 bucket, you can transform it into a fully functional web server.
Understanding Websites and Static Content
When a user visits a URL, the browser sends an HTTP GET request to a web server, which responds with an HTML file that the browser renders. A complete website typically includes:
- HTML: Structures your content.
- CSS: Styles and formats the display.
- JavaScript: Adds dynamic functionality.
- Assets: Incorporates images, videos, audio, and other media.
Since S3 can store all these elements as objects, you can host an entire website simply by uploading the necessary files to your bucket.
Enabling Static Website Hosting on S3
S3 allows you to serve static websites by hosting your HTML, CSS, and JavaScript files. Once you enable static website hosting, S3 provides a URL that grants HTTP access to your site.
Static Content Only
S3 static website hosting is designed solely for static content. If your website requires server-side processing or dynamic content rendering, consider using services like Amazon EC2, Amazon ECS, or AWS Lambda.
For those wishing to leverage a custom domain instead of the S3-provided URL, note that your bucket must be named exactly as your custom domain. For example, for the domain bestcars.com, your S3 bucket should also be named bestcars.com.
Pricing Considerations
When hosting a static website on S3, you incur standard S3 fees, which include:
- Storage Costs: Charged per gigabyte of stored data.
- Data Transfer Costs: Charged per gigabyte for outbound data.
- Per Request Charges: Each HTTP request (e.g., GET) is billed at a minimal rate (e.g., $0.0004 per 1,000 GET requests at the time of recording).
Accessing Your Static Website
Once static website hosting is enabled, your S3 bucket provides an access URL with the following pattern:
http://bucketname.s3-website-<region-name>.amazonaws.com
For instance, if your bucket is named "mybucket" in the us-east-1 region, your website URL will be:
http://mybucket.s3-website-us-east-1.amazonaws.com
If you opt for a custom domain to create a more memorable URL, set up Amazon Route 53 and ensure that your bucket name exactly matches your domain (for example, bestcars.com).
Summary
Amazon S3 static website hosting enables you to serve your static website files—HTML, CSS, JavaScript, and media—directly from an S3 bucket. Key takeaways include:
- S3 static website hosting is intended for static content only; server-side logic isn't supported.
- Standard S3 pricing applies, covering storage, data transfer, and per-request fees.
- The provided URL format is:
http://bucketname.s3-website-<region-name>.amazonaws.com
- To use a custom domain, the bucket must have the same name as the domain, with Amazon Route 53 facilitating DNS routing.
Watch Video
Watch video content