Fun Projects to Leverage AWS
Part -1
Hey Everybody! I hope you all are doing fantastic.
Introduction
Embarking on the journey to learn Amazon Web Services (AWS) is an exciting and rewarding endeavor, offering numerous possibilities for those eager to enhance their cloud computing skills. To make the learning experience more engaging, I have curated 5 fun projects, to showcase the versatility of AWS and gain hands-on experience in deploying real-world solutions. Let’s start with project -1 and then 2,3,4, and so on to the next blogs. For that, you can visit to this YouTube channel:
https://www.youtube.com/@ITCorporate_Couple
Project # 1 — Launch a static website on Amazon S3
Discover an affordable and efficient way to host your website by deploying a static site on Amazon S3 — an ideal introduction to key AWS services. Create an S3 bucket to leverage simplicity and scalability, and enhance global accessibility using Amazon CloudFront as your CDN. Seamlessly manage your domain with Amazon Route 53, and implement SSL/TLS security through AWS Certificate Manager for a secure HTTPS connection, ensuring optimal performance and security for your website.
Before deploying, make sure your static website files (HTML, CSS, JavaScript, images, etc.) are ready in a local directory.
Create an S3 Bucket
- Go to the AWS Management Console.
- Navigate to S3 and click on “Create bucket.”
- Enter a unique bucket name, select a region, and click “Next.”
- On the “Configure options” page, click “Next.”
- You can configure bucket policies on the “Set permissions” page if needed. Click “Next” to review, then click “Create bucket.”
OR
aws s3api create-bucket --bucket YOUR_UNIQUE_BUCKET_NAME --region YOUR_REGION
Upload Your Website to the S3 Bucket
- Open your newly created S3 bucket.
- Click on the “Upload” button and select all your website files.
- Ensure that the files are set to be publicly accessible. You can do this by selecting each file, clicking on “Actions,” and choosing “Make public.”
OR
aws s3 sync YOUR_LOCAL_WEBSITE_DIRECTORY s3://YOUR_UNIQUE_BUCKET_NAME --acl public-read
Enable Static Website Hosting on the S3 Bucke
- In the S3 bucket, go to the “Properties” tab.
- Click on “Static website hosting.”
- Select “Use this bucket to host a website.”
- Set the “Index document” to your main HTML file (e.g.,
index.html
) and optionally set the "Error document." - Save the changes.
OR
aws s3 website s3://YOUR_UNIQUE_BUCKET_NAME --index-document index.html
Configure Amazon CloudFront Distribution
- Go to the CloudFront console.
- Click “Create Distribution.”
- Choose “Web” distribution.
- Set the following configurations:
- Origin Domain Name: Select your S3 bucket from the dropdown.
- Default Root Object: Set it to your main HTML file (e.g.,
index.html
). - Leave other settings as default or adjust based on your requirements.
5. Click “Create Distribution.”
OR
import boto3
cloudfront_client = boto3.client('cloudfront')distribution_config = {
'CallerReference': 'your-unique-caller-reference',
'Origins': {
'Quantity': 1,
'Items': [
{
'Id': 'S3-origin',
'DomainName': 'YOUR_UNIQUE_BUCKET_NAME.s3.amazonaws.com',
'S3OriginConfig': {
'OriginAccessIdentity': ''
}
}
]
},
'DefaultCacheBehavior': {
'TargetOriginId': 'S3-origin',
'ForwardedValues': {
'QueryString': False,
'Cookies': {'Forward': 'none'},
'Headers': {'Quantity': 0}
},
'TrustedSigners': {'Enabled': False, 'Quantity': 0},
'ViewerProtocolPolicy': 'allow-all',
'MinTTL': 0
},
'Comment': 'Your CloudFront Distribution Comment',
'Enabled': True
}response = cloudfront_client.create_distribution(DistributionConfig=distribution_config)
distribution_id = response['Distribution']['Id']print(f"CloudFront Distribution ID: {distribution_id}")
Update Amazon Route 53 for Your Domain
- Go to the Route 53 console.
- Create a new hosted zone for your domain if you haven’t already.
- Note the four nameservers provided for your hosted zone.
- In your domain registrar’s settings, update the nameservers to the ones provided by Route 53.
Obtain an SSL/TLS Certificate using AWS Certificate Manager (ACM)
- Go to the ACM console.
- Click “Request a certificate.”
- Enter your domain name and follow the instructions to validate ownership.
- Once validated, select the option to create a new CloudFront distribution.
- Choose the CloudFront distribution you created earlier and complete the certificate request.
OR
import boto3
acm_client = boto3.client('acm')certificate_arn = acm_client.request_certificate(
DomainName='yourdomain.com',
ValidationMethod='DNS'
)['CertificateArn']print(f"Certificate ARN: {certificate_arn}")
Update CloudFront Distribution to Use SSL/TLS
- Go to the CloudFront console.
- Select your distribution and click “Edit.”
- Under the “General” tab, change the “Viewer Protocol Policy” to “Redirect HTTP to HTTPS.”
- Save the changes.
OR
cloudfront_client = boto3.client('cloudfront')
cloudfront_client.update_distribution(
DistributionConfig={
'DistributionConfig': {
'DefaultCacheBehavior': {
'ViewerProtocolPolicy': 'redirect-to-https'
}
},
'Id': 'YOUR_CLOUDFRONT_DISTRIBUTION_ID',
'IfMatch': 'your-distribution-config-if-match'
}
)
Wait for Changes to Propagate
It may take some time for changes to propagate. Once complete, your static website should be accessible via the custom domain over HTTPS globally through CloudFront.
Congratulations! You’ve successfully deployed a static website on Amazon S3, configured CloudFront for global content delivery, and set up DNS with Route 53 and SSL/TLS with ACM.
#follow for more such projects to learn AAWS. All the best!