All Articles

aws html file deployment

1. Deployment html file to AWS S3

In this article, the configuration of AWS S3 and CloudFront will be shown. s3

First, prepare for the source codes you want to deploy.

create bucket 1

check 2 red boxes if you want to lock the object, but it doesn’t need to be checked in this example. 2

Upload html files 3 4

check the files using the aws cli

https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects.html

5

Currently, the following object url is not public. It means that the url is not permitted.

6 6_2

2. Setting permissions

I will not use the ACL, so I checked the 2 top boxes.

7

confirm the block access settings and go to Bucket Policy.

7_2 7_3

Input the following information and generate the policy.

Origin domain name : select a bucket you made
Object Caching : Customize
Default Root Object : index.html

8

Copy the JSON and paste it to the policy editor.

8_2

Now, I can access the website using the object url. We will combine S3 with the CloudFront and this access will be diabeld. 8_3

3. Static website hosting

Go to the Properties tab and Check “Use this bucket to host a website”

99

Now we can use that endpoint.

Enable the versioning to manage the history.

This event option is important because we can use that to get some events and process it. For example, an image is deleted on S3 and then we need to delete the related information on Dynamo DB. In that case, this option will be useful for that.

9_2

4. CloudFront Distribution

https://aws.amazon.com/cloudfront/ https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html

[CloudFront] -> [Create Distribution] -> [Get Started]

https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html

10

Origin domain name : select a bucket you made
Object Caching : Customize
Default Root Object : index.html

10_2

[CloudFront] -> [ID] -> [Origins and Origin Groups] -> [Edit] -> [Restrict Bucket Access] -> [Yes]

10_3

10_4

After fishing deploying, go to the policy of the bucket permissions to check the modification. Now it doesn’t allow the access to the html file using the object URL and the endpoint of static website hosting.

11 11_2

Finally, the domain name of CloudFront can be used to connect the index html on S3. 12