Q.
Project 1:Host the static website in s3 and enable cloud distribution globally
To host a static website in Amazon S3 and enable global distribution using AWS
CloudFront, follow these steps:
Step 1: Create an S3 Bucket
Login to AWS Management Console.
Navigate to S3:
Go to the S3 service from the AWS Management Console.
Create a New Bucket:
Click on "Create bucket".
Enter a unique bucket name (e.g., my-static-website-bucket).
Select the AWS region where you want the bucket to be created.
Keep other settings as default unless you have specific requirements.
Click "Create bucket".
Step 2: Configure the Bucket for Static Website Hosting
Enable Static Website Hosting:
Select your bucket.
Go to the "Properties" tab.
Scroll down to the "Static website hosting" section.
Click "Edit".
Select "Enable" and provide the index document (e.g., [Link]). You can also
specify an error document (e.g., [Link]).
Save changes.
Upload Your Website Files:
Go to the "Objects" tab.
Click on "Upload" and add your website files (e.g., HTML, CSS, JavaScript, images).
Click "Upload" to transfer the files to S3.
Step 3: Set Permissions for the Bucket
Make the Bucket Public:
Go to the "Permissions" tab of your bucket.
Scroll to the "Bucket policy" section and click "Edit".
Add a bucket policy to allow public read access. Example policy:
json
Copy code
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s[Link]my-static-website-bucket/*"
}
]
}
Replace my-static-website-bucket with your bucket name.
Save the changes.
Step 4: Create a CloudFront Distribution
Navigate to CloudFront:
Go to the CloudFront service from the AWS Management Console.
Create a Distribution:
Click on "Create Distribution".
Choose "Web" as the delivery method.
Configure Distribution Settings:
Origin Domain Name: Select your S3 bucket from the list.
Viewer Protocol Policy: Choose Redirect HTTP to HTTPS for better security.
Cache Policy: Use the default settings or customize as needed.
Default Root Object: Enter [Link] if necessary.
Origin Access: You can create an Origin Access Control (OAC) for additional
security to restrict access to the S3 bucket through CloudFront only.
Click "Create Distribution".
Step 5: Update DNS Settings (Optional)
Configure DNS:
If you have a custom domain, you can use Route 53 or another DNS service to point
your domain to the CloudFront distribution.
Create an A or CNAME record in your DNS settings to map your domain to the
CloudFront distribution domain name.
Step 6: Test Your Website
Access Your Website:
Once CloudFront finishes deploying (it may take some time), access your website
using the CloudFront distribution domain name.
Ensure all the content is loading correctly.