Devops/AWS

[AWS] CloudFront + S3 + git actions ๋ฐฐํฌ ์˜ค๋ฅ˜ Invalidate CloudFront Cache

yuri lee 2023. 1. 31. 20:48
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š”  CloudFront + S3 + git actions ๋ฐฐํฌ ์˜ค๋ฅ˜์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ธฐ์กด ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์ˆ˜์ • ์š”์ฒญ์‚ฌํ•ญ ์—…๋ฌด๊ฐ€ ๋“ค์–ด์™€, ํ•ด๋‹น ์—…๋ฌด ์ฒ˜๋ฆฌ ํ›„ ๋‹ค์‹œ git actions ์„ ์‚ฌ์šฉํ•ด ๊ฐœ๋ฐœ ์„œ๋ฒ„ ๋ฐฐํฌ๋ฅผ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ ๋กœ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์€ " CloudFront + S3 + git actions" ์ž…๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฐ๋ฐ..! ๊ฐ‘์ž๊ธฐ ์•„๋ž˜ git actions deploy.yml ์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ์กด์—๋Š” ๋ณธ์ ์ด ์—†๋˜ ์˜ค๋ฅ˜๋ผ ๋ฐ”๋กœ ๊ตฌ๊ธ€๋ง์„ ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

  - name: Invalidate CloudFront Cache
    run: aws cloudfront create-invalidation --distribution-id ${{secrets.DEV_DISTRIBUTION_ID}} --paths "/*"

 

How to solve the problem

๊ตฌ๊ธ€๋ง ๊ฒฐ๊ณผ CloudFront์—์„œ ๋ฐฐํฌํ•œ ๋Œ€์ƒ์œผ๋กœ ๋“ค์–ด๊ฐ€ ๋ฌดํšจํ™” ํƒญ์„ ํด๋ฆญ ํ›„, ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฌดํšจํ™”๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๋ฉด ๋œ๋‹ค๊ณ  ํ•˜๋„ค์š”. ์ ์šฉ ํ›„, ๋‹ค์‹œ git actinos์œผ๋กœ ๋ฐฐํฌํ•ด๋ดค๋Š”๋ฐ, ์ •์ƒ ์ž‘๋™ํ•˜์˜€์Šต๋‹ˆ๋‹ค. 

/*

 

+) ๋ฌดํšจํ™”(invalidation)๋ž€?

๋ฌดํšจํ™”(invalidation)๋ž€ ์บ์‹œ๋ฅผ ๊ฐ•์ œ๋กœ ์ง€์šฐ๋Š” ๊ฒƒ์„ ๋œปํ•ฉ๋‹ˆ๋‹ค.

 

Conclusion

๋ฐฐํฌํ•˜๋Š” ๊ณผ์ •์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด..์ •๋ง ์‹์€๋•€์ด ํ๋ฅด๋Š”๋ฐ, ์ด๋ฒˆ์—๋Š” ๋นจ๋ฆฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ ์ฐพ์€ ๊ฒƒ ๊ฐ™์•„ ๋‹คํ–‰์ด์˜€์Šต๋‹ˆ๋‹ค. โœŒ

๋ฐ˜์‘ํ˜•