Learnt about IaaC and here are the important points that should be mentioned
-
What is IaaC? It is basically having your cloud configuration or infrastructure to find a source control like GitHub.
-
Benefits :
- Team Collaboration
- Disaster Recovery (Chaos Engineering)
- History of Changes (Version Controlling)
-
Tools :
- CloudFormation (AWS specific)
- AWS SAM (AWS Specific)
- Terraform (Works with every Cloud service)
- Pulumi (Not very popular, but similar to Terraform)
Apart from that, I deployed my sample resume site using AWS SDK
- Deployment
- Public Visibility
Here are the steps to deploy the HTML website in AWS :
-
To know the previous steps on How to Deploy S3 using AWS SAM, Click on Day-2
-
Add the following Snippet to the
template.yaml
below the resource tag (This creates a bucket named "ronit-demo-site", whose static website hosting is set to "Enabled")
MyWebsite:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
BucketName: ronit-demo-site
-
Now make a folder for the HTML-CSS file and create the "index.html" inside that folder
-
Then, for a bit of automation, I updated the
MakeFile
to avoid repetition of CLI commands (Simply makes our lives easier, So why not?... Hehe)
Here is the snippet for the "MakeFile"
.PHONY: build
build:
sam build
deploy-infra:
sam build && aws-vault exec ronitblenz --no-session -- sam deploy
deploy-site:
aws-vault exec ronitblenz --no-session -- aws s3 sync ./resume-site s3://ronit-demo-site
- Now run command
make deploy-site
It uploads the .html file in the S3 Bucket
But here is the catch, A case-study while clicking on the public S3 link :
-
Before uploading the .html file, it displayed
Error 404 Not Found
It means, file does not exist! -
After uploading the .html file, it displayed
Error 403 Forbidden
It means, file exists but not accessible, permission not granted
- Now I had to add Bucket Policies to the
template.yaml
file below MyWebsite tag (This helps to make all files in S3 Bucket accessible to the link) Here is the snippet to be added :
BucketPolicy:
Type: AWS::S3::BucketPolicyProperties:
PolicyDocument:
Id: MyPolicyVersion: 2012-10-17Statement:
- Sid: PublicReadForGetBucketObjectsEffect: AllowPrincipal: "*"Action: "s3:GetObject"Resource: !Join- ""- - "arn:aws:s3:::"- !RefMyWebsite- /*Bucket: !Ref MyWebsite
- Now run command
make deploy-infra
AND HOLA! You have successfully deployed your site on AWS.