๐Ÿ“‚ AWS/AWS Developer - Associate

[AWS] Developer Associate #7 CloudFront

dhyuck 2024. 8. 3. 02:27
๋ฐ˜์‘ํ˜•

CDN์ด๋ž€?

  • CDN(Content Delivery Network)์€ ์‚ฌ์šฉ์ž์™€ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ๊ฐ€๊นŒ์šด ๊ณณ์— ์บ์‹œ ์„œ๋ฒ„๋ฅผ ์šด์˜ํ•˜์—ฌ ์ปจํ…์ธ ๋ฅผ ๋น ๋ฅด๊ฒŒ ์ „์†กํ•˜๋Š” ์บ์‹ฑ ๊ธฐ์ˆ ์ž…๋‹ˆ๋‹ค.
  • CDN์€ ํด๋ผ์ด์–ธํŠธ์™€ ์„œ๋ฒ„ ๊ฐ„์— ์ค‘๊ฐœ ์„œ๋ฒ„(intermediary servers)๋ฅผ ๋‘์–ด latency๋ฅผ ์ค„์ด๊ณ  ํ†ต์‹  ๊ณผ์ •์—์„œ delay๋ฅผ ์ค„์ด๋Š” ๊ฒƒ์ด ๋ชฉ์ ์ž…๋‹ˆ๋‹ค.
  • CDN์„ ์‚ฌ์šฉํ•˜๋ฉด ์‚ฌ์šฉ์ž๋Š” ์ง€๋ฆฌ์ ์œผ๋กœ ๊ฐ€๊นŒ์šด CDN ์„œ๋ฒ„์—์„œ ์ €์žฅ๋œ ์ฝ˜ํ…์ธ ๋ฅผ ์ œ๊ณต๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  • CDN์€ ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ๋Ÿ‰์ด ๋งŽ์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์›น ํŽ˜์ด์ง€ ๋กœ๋“œ ์†๋„๋ฅผ ๋†’์ด๋Š” ์„œ๋ฒ„ ๋„คํŠธ์›Œํฌ๋กœ ์ฝ˜ํ…์ธ  ์ „์†ก ๋„คํŠธ์›Œํฌ ๋˜๋Š” ์ฝ˜ํ…์ธ  ๋ฐฐํฌ ๋„คํŠธ์›Œํฌ๋ฅผ ์˜๋ฏธํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
  • AWS๋Š” CDN ์„œ๋น„์Šค๋กœ CloudFront๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

CloudFront๋ž€?

  • Cloud Front๋Š” AWS์˜ CDN ์„œ๋น„์Šค๋กœ Edge Location์ด๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ๋ฐ์ดํ„ฐ ์„ผํ„ฐ์˜ ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด ์ปจํ…์ธ ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.
  • Edge Location์€ ์‹ค์ œ ๋ฐ์ดํ„ฐ๊ฐ€ ์บ์‹ฑ๋˜๋Š” ์žฅ์น˜์ž…๋‹ˆ๋‹ค.
  • CloudFront๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์— ์‚ฌ์šฉ์ž๊ฐ€ ์ฝ˜ํ…์ธ ๋ฅผ ์š”์ฒญํ•˜๋ฉด ์ง€์—ฐ ์‹œ๊ฐ„์ด ๊ฐ€์žฅ ๋‚ฎ์€ Edge Location์œผ๋กœ ์š”์ฒญ์ด ๋ผ์šฐํŒ…๋˜์–ด ์„ฑ๋Šฅ์ด ํ–ฅ์ƒ๋ฉ๋‹ˆ๋‹ค.
  • Origin์€ ์ปจํ…์ธ ๊ฐ€ ์ €์žฅ๋˜๋Š” ์œ„์น˜์ด๋ฉฐ CloudFront๊ฐ€ ์‚ฌ์šฉ์ž๊ฐ€ ์ œ๊ณตํ•  ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ณณ์ž…๋‹ˆ๋‹ค.
  • Origin์€ S3, ALB, Lambda function URL, EC2, Custom Origin(HTTP), MediaSotre, MediaPackage๊ฐ€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • Distribution์€ CloudFront๋ฅผ ํ†ตํ•ด ์ปจํ…์ธ ๋ฅผ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์„ ํฌํ•จํ•˜๋Š” ๋…ผ๋ฆฌ์  ๋‹จ์œ„์ž…๋‹ˆ๋‹ค.
  • Distribution์€ CloudFront์— ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ฌ Origin๊ณผ ๋™์ž‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค์ฃผ๋Š” ์„ค์ •์ž…๋‹ˆ๋‹ค.
  • Distribution์€ Origin, Cache Behavior ๋“ฑ์œผ๋กœ ๊ตฌ์„ฑ๋˜๊ณ  1๊ฐœ์˜ Distribution์€ ์ตœ๋Œ€ 25๊ฐœ์˜ Origin์„ ์กฐํ•ฉํ•˜์—ฌ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Distribution์„ ์ƒ์„ฑํ•˜๋ฉด d111111abcdef8.cloudfront.net๊ณผ ๊ฐ™์€ ๋„๋ฉ”์ธ์ด ํ• ๋‹น๋ฉ๋‹ˆ๋‹ค.

CloudFront - Origin

  • CloudFront๋Š” Origin์œผ๋กœ S3 Bucket, S3 Object Lambda, S3 Access Point๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ ์ž์ฃผ ์ ‘๊ทผํ•˜๋Š” ๊ฐ์ฒด๋Š” CloudFront๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค. CloudFront๋Š” S3์— ๋น„ํ•ด ๋ฐ์ดํ„ฐ ์ „์†ก ๊ฐ€๊ฒฉ์ด ์ €๋ ดํ•˜๊ณ  ์‚ฌ์šฉ์ž์™€ ๋” ๊ฐ€๊นŒ์šด ๊ณณ์— ์ €์žฅ๋˜์–ด ์ง€์—ฐ์‹œ๊ฐ„์ด ์ค„์–ด๋“ค๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
  • CloudFront๋Š” S3 origin์— ์ธ์ฆ๋œ ์š”์ฒญ์„ ์ „์†กํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ Origin Access Control(OAC)์™€ Origin Access Identity(OAI)๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. OAC๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด best practice์ž…๋‹ˆ๋‹ค.
  • CloudFront๋Š” Origin์œผ๋กœ Internet-facing ALB๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. (Internal ALB๋Š” Origin์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.)
  • ์‚ฌ์šฉ์ž๊ฐ€ CloudFront๋ฅผ ์šฐํšŒํ•˜์—ฌ ALB์— ์ ‘๊ทผํ•˜๋Š” ๊ฑธ ๋ง‰๊ธฐ ์œ„ํ•ด์„œ AWS-managed prefix๋ฅผ ALB์˜ SG์— ๋“ฑ๋กํ•˜๊ฑฐ๋‚˜ ALB๊ฐ€ ํŠน์ • HTTP ํ—ค๋”๋ฅผ ํฌํ•จํ•œ ์š”์ฒญ๋งŒ ์‘๋‹ตํ•˜๋„๋ก ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • CloudFront๋Š” Origin์œผ๋กœ EC2, Custom Origin, Lambda function URL์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Custom Origin์€ Public DNS ์ด๋ฆ„์ด ์žˆ๋Š” HTTP(S) ์›น ์„œ๋ฒ„์ž…๋‹ˆ๋‹ค.
  • S3 Static website endpoint๋„ Custom origin์œผ๋กœ ๊ฐ„์ฃผ๋ฉ๋‹ˆ๋‹ค.
  • Lambda function URL์€ Lambda function์„ ์œ„ํ•œ ์ „์šฉ HTTPS endpoint์ž…๋‹ˆ๋‹ค.

CloudFront - Orgin Group

  • ๊ณ ๊ฐ€์šฉ์„ฑ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ Origin Group์„ ์‚ฌ์šฉํ•˜์—ฌ Origin fail-over๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Origin Group์€ Primary origin๊ณผ Secondary origin์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • Primary origin์ด fail-over๋ฅผ ์œ„ํ•ด ์„ค์ •ํ•œ HTTP status code๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒฝ์šฐ ๋˜๋Š” Primary origin์— ์—ฐ๊ฒฐ์— ์‹คํŒจํ•˜๊ฑฐ๋‚˜ ์‘๋‹ต์ด ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” ๊ฒฝ์šฐ์— CloudFront๋Š” Secondary origin์œผ๋กœ ๋ผ์šฐํŒ…ํ•ฉ๋‹ˆ๋‹ค.

Cache Key์™€ Cache Policy

  • Cache Key๋Š” Cache์— ์กด์žฌํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ์œ ์ผํ•˜๊ฒŒ ์‹๋ณ„ํ•˜๋Š” ๊ฐ’์œผ๋กœ CloudFront๋Š” Cache Key๋กœ Cache Hit์ธ์ง€ Cache Miss ์ธ์ง€ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
  • Default cache key๋Š” CloudFront distribution์˜ domain name๊ณผ ์š”์ฒญ URL ๊ฒฝ๋กœ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • Cache Policy๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Cache key์— HTTP ํ—ค๋”, cookie, query string ๋“ฑ์„ ํฌํ•จ์‹œ์ผœ Custom cache key๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Custom cache key๋ฅผ ์ž˜๋ชป ์ง€์ •ํ•˜๊ฒŒ ๋˜๋ฉด ์ค‘๋ณต๋œ ๊ฐ์ฒด๋ฅผ ์บ์‹ฑํ•˜๊ณ  cache hit ๋น„์œจ์„ ๋‚ฎ์ถ”๊ณ  origin request ์ˆ˜๋ฅผ ๋Š˜๋ฆฌ๋Š” ๋“ฑ์˜ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. User-agent ๋˜๋Š” ์‚ฌ์šฉ์ž๋ณ„ session id ๋“ฑ์„ cache key์— ํฌํ•จ์‹œํ‚ค๋ฉด ์•ˆ ๋ฉ๋‹ˆ๋‹ค.
  • Cache Policy๋Š” ์ผ๋ฐ˜์ ์ธ ์‚ฌ๋ก€์— ์ ํ•ฉํ•œ Managed policy์™€ Custom policy๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

CloudFront Cache behavior์™€ Invalidation

  • Cache behavior๋ฅผ ์„ค์ •ํ•˜์—ฌ URL ๊ฒฝ๋กœ ํŒจํ„ด์— ๋”ฐ๋ผ์„œ ๋‹ค์–‘ํ•œ Origin์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Cache behavior๋Š” Path pattern, Origin ๋˜๋Š” Origin group, ์‚ฌ์šฉ์ž๊ฐ€ ์š”์ฒญํ•˜๋Š” ํ”„๋กœํ† ์ฝœ, ํ—ˆ์šฉ๋˜๋Š” HTTP ๋ฉ”์„œ๋“œ ๋“ฑ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Path pattern๊ณผ ์ˆœ์„œ๋ฅผ ์ž˜๋ชป ์ •์˜ํ•˜๋ฉด ์‚ฌ์šฉ์ž์—๊ฒŒ ์›์น˜ ์•Š๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์ฃผ์˜ ๊นŠ๊ฒŒ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • ์—ฌ๋Ÿฌ๊ฐœ์˜ behavior๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ๊ธฐ๋ณธ ํŒจํ„ด(*)์€ ํ•ญ์ƒ ๋งˆ์ง€๋ง‰์œผ๋กœ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.
  • Invalidation์„ ์‚ฌ์šฉํ•˜๋ฉด ์บ์‹œ๊ฐ€ ๋งŒ๋ฃŒ๋˜๊ธฐ ์ „์— ์บ์‹ฑ ๋œ ์ฝ˜ํ…์ธ ๋ฅผ ์‚ญ์ œํ•˜์—ฌ ์ฝ˜ํ…์ธ ๋ฅผ ๊ฐฑ์‹ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    Invalidation์€ ๋น„์šฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

CloudFront Signed Cookie/URL

  • Signed URL๊ณผ Signed cookie๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋น„๊ณต๊ฐœ ์ปจํ…์ธ ๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ค์น˜ ํŒŒ์ผ๊ณผ ๊ฐ™์€ ๊ฐœ๋ณ„ ํŒŒ์ผ์— ๋Œ€ํ•œ ์•ก์„ธ์Šค๋ฅผ ์ œ๊ณตํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋Š” Signed URL์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
  • ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํŒŒ์ผ์— ๋Œ€ํ•œ ์•ก์„ธ์Šค๋ฅผ ์ œ๊ณตํ•˜๋ ค๋Š” ๊ฒฝ์šฐ์—๋Š” Signed cookie๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
  • Signed Cookie/URL์„ ๋งŒ๋“œ๋ ค๋ฉด signer๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. signer๋Š” CloudFront์—์„œ ๋งŒ๋“  ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” key group์ด๊ฑฐ๋‚˜ CloudFront key pair๊ฐ€ ํฌํ•จ๋œ AWS account์ž…๋‹ˆ๋‹ค. ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” key group์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

CloudFront Geo restriction

  • Geo restriction(๋˜๋Š” Geo Blocking)๋Š” ์‚ฌ์šฉ์ž์˜ ์ง€๋ฆฌ์  ์œ„์น˜์— ๋”ฐ๋ผ CloudFront๋กœ ์ ‘๊ทผํ•  ์‚ฌ์šฉ์ž๋ฅผ ์ œํ•œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Allow list๋ฅผ ์ง€์ •ํ•˜์—ฌ ํ—ˆ์šฉํ•  ๊ตญ๊ฐ€๋ฅผ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ Block list๋ฅผ ์ง€์ •ํ•˜์—ฌ ์ฐจ๋‹จํ•  ๊ตญ๊ฐ€๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • CloudFront์˜ geographic restriction์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ third-party geolocation service๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ œํ•œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž์˜ ์œ„์น˜๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ CloudFront๋Š” ์š”์ฒญํ•œ ์ปจํ…์ธ ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

CloudFront Logging

  • CloudFront๋Š” Standard log(access log) ๋˜๋Š” Real-time log ๋ฐฉ์‹์œผ๋กœ request logging์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • Standard log๋Š” S3๋กœ ์ „๋‹ฌ๋˜๊ณ  Real-time log๋Š” Kinesis Data Stream์œผ๋กœ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.
  • Standard log์™€ Real-time log๋Š” best-effor์— ๊ธฐ๋ฐ˜ํ•˜์—ฌ ์ „์†กํ•˜๋ฉฐ ๋กœ๊ทธ ๋ ˆ์ฝ”๋“œ๊ฐ€ ๋ˆ„๋ฝ๋˜๊ฑฐ๋‚˜ ํ•œ์ฐธ ๋’ค์— ์ ์žฌ๋  ์ˆ˜ ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
  • CloudFront request log๋ฅผ ๋ชจ๋‘ ๋ถ„์„ํ•˜๊ธฐ ๋ณด๋‹ค๋Š” ์ปจํ…์ธ ์— ๋Œ€ํ•œ request ํŠน์„ฑ์„ ์ดํ•ดํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๊ธฐ๋ฅผ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•