The images in my posts are currently stored as PNG files in the public folder and loaded with the <Image> component. As the number of images grows, the project gets larger and the files become harder to manage. Image-heavy pages can also load more slowly. I looked for a better way to serve those images.
) stores content on servers around the world and serves it from a location close to the user. This speeds up delivery and reduces the load on the origin server.
Wikipediaโ
, such as HTML, CSS, JavaScript, and images, through a global network of data centers called edge locations. When a user requests content, CloudFront routes the request to an edge location that can serve it with low latency.
Amazon S3
is an object storage service with a web interface for storing and retrieving data at scale.
I already had a domain hosted in Route 53, so I used the same AWS account.
Sign in to AWS, open S3, and click ๋ฒํท ์์ฑ (Create bucket).
Check the region before creating the bucket.
I chose ์์์ ํํ์(์์ธ) (Asia Pacific, Seoul).
See the bucket naming rulesโ. For example, underscores are prohibited.
Leave the remaining settings at their defaults. Click ๋ฒํท ๋ง๋ค๊ธฐ (Create bucket) to finish.
Open CloudFront and click ๋ฐฐํฌ ์์ฑ (Create distribution).
Under Origin Domain, select the S3 bucket endpoint. Under Origin Access, choose ์๋ณธ ์์ธ์ค ์ ์ด ์ค์ (Origin access control settings), then click Create new OAC.
Leave the default settings and click Create.
Choose a viewer protocol policy for the default cache behavior. I chose HTTPS only.
Basic image loads and classic scripts usually work with the default cache policy. To support requests that need CORS, I configured the following policies.
Set the origin request policy to CORS-S3Origin.
Set the response headers policy to CORS-With-Preflight.
I left the web application firewall (WAF) disabled for this setup because it can add charges.
Finish any other settings you need and click ๋ฐฐํฌ ์์ฑ (Create distribution).
Open Route 53 and select your domain. Click ๋ ์ฝ๋ ์ธํธ ์์ฑ (Create record set), enter your subdomain, and select a CNAME record. Set its value to the CloudFront distribution domain and create the record.
Open AWS Certificate Manager (ACM) to request the certificate CloudFront needs. Request it in the
US East (N. Virginia)
region.
Switch to N. Virginia before continuing.
Choose Request certificate, then Request a public certificate. Enter the domain you configured with the CNAME record and click ์์ฒญ (Request).
The certificate initially shows Pending validation. If the status does not change, click Route53์์ ๋ ์ฝ๋ ์์ฑ (Create records in Route 53) to create the validation record.