Using HTTPS with Cloudfront
약 1 분
Using HTTPS with Cloudfront
First, we will issue an SSL certificate from AWS Certificate Manager (ACM).
- Go into AWS Certificate Manager (ACM).
- Click Request Certificate and select Request Public Certificate.
- Enter the domain name (purchased domain) and click the Request button at the bottom.
Now let's set up CloudFront.
- CloudFront Click the Create CloutFront distribution button.
- Select the source domain and click Use website endpoint.
- Select HTTP only for Protocol and enter
{{domain}}.s3-website.ap-northeast-2.amazonaws.com
for Name. No EC2 server or S3 work required for HTTPS. - Select Viewer Protocol Policy =>
Redirect HTTP to HTTPS
in Default Cache Behavior. - Select Web Application Firewall. In my case, I selected Enable and also selected Use Monitor mode.
- In Settings, select the price category you want. In my case, I selected 'Used in North America, Europe, Asia, Middle East and Africa'.
- Click Add Alternate Domain Name (CNAME) entry and enter the {domain.com} domain.
- For 'Custom SSL Certificate', select the certificate issued by ACM.
CloudFront setup is finished.
Now let's go back to Route53 and add another routing record for CloudFront.
- S3 => Delete the record that allowed http://domain.com to be accessed by Route53.
- Click Create Record in Route53.
- Turn on the alias switch and select 'Alias for CloudFront distribution' as the traffic route destination.
- Click Select Distribution to select a cloudfront domain name and create a record.
::: tips
S3 => Route53 is using http,
S3 => Cloudfront => Route53 is https use.
This is the code to invalidate the cache in github actions. Just run it after the S3 upload.aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_DISTRIBUTION_ID }} --paths "/*"
AWS_DISTRIBUTION_ID is your Cloudfront ID.
:::
Now you can check that https://domain.com is entering well.