5.
Deploying a Static Site Using AWS S3
and CloudFront
Amazon S3 can be used to host static websites, and CloudFront can be used to distribute the
content globally with caching for faster access. Here's how to set up a simple static website
using AWS S3 and CloudFront:
1. Create S3 Bucket:
- Log into AWS Management Console.
- Navigate to S3, create a new bucket, and enable "Static website hosting."
- Upload your HTML, CSS, and JavaScript files.
2. Set Bucket Permissions:
- Go to the "Permissions" tab and set the bucket policy to allow public access to the static
files.
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}
```
3. Configure CloudFront:
- Go to CloudFront, create a new distribution, and select your S3 bucket as the origin.
- Set the default root object (e.g., `index.html`).
4. Deploy:
- After configuration, your static site will be distributed globally with CloudFront, ensuring
fast access for users worldwide.