๐Ÿ“‚ AWS/AWS Developer - Associate

[AWS] Developer Associate #1 Elastic Beanstalk

dhyuck 2024. 3. 6. 23:10
๋ฐ˜์‘ํ˜•

Elastic Beanstalk์ด๋ž€?

  • Elastic Beanstalk์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์ค‘์‹ฌ์˜ ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.
  • Elastic Beanstalk๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋Š” ํ™˜๊ฒฝ(์ธํ”„๋ผ)์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์ง€ ๋ชปํ•ด๋„ AWS์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹ ์†ํ•˜๊ฒŒ ๋ฐฐํฌํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์—…๋กœ๋“œํ•˜๊ธฐ๋งŒํ•˜๋ฉด Elastic Beanstalk์—์„œ ์ปดํ“จํŒ… ๋ฆฌ์†Œ์Šค๋ฅผ ์ค€๋น„ํ•˜๊ณ , ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ๊ณผ ์šฉ๋Ÿ‰ ํ™•์žฅ(scaling), ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ƒํƒœ ๋ชจ๋‹ˆํ„ฐ๋ง์„ ์ž๋™์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
  • Beanstalk๋Š” JAVA, Tomcat, Python, Go, Node.js, Ruby, PHP, Docker, .Net Core on Linux, .Net on Windows ๋“ฑ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • Beanstalk ์ž์ฒด๋Š” ๋ฌด๋ฃŒ์ด์ง€๋งŒ ASG, ELB ๋“ฑ์— ๋Œ€ํ•ด์„œ ์š”๊ธˆ์„ ์ง€๋ถˆํ•ฉ๋‹ˆ๋‹ค.
  • Beanstalk๋Š” 1๊ฐœ์˜ ์ธํ„ฐํŽ˜์ด์Šค์—์„œ EC2, ASG, ELB, RDS ๋“ฑ์˜ ์„œ๋น„์Šค๋ฅผ ์•Œ์•„์„œ ๋ฐฐํฌํ•˜๋Š” Managed service์ž…๋‹ˆ๋‹ค.
  • Beanstalk์€ ๋‚ด๋ถ€์ ์œผ๋กœ cloudformation ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
  • Beanstalk์€ ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ๋ฐฐํฌ ์˜ต์…˜์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Elastic Beanstalk์˜ ๊ฐœ๋…(concepts)

Application

  • Environments, Versions, Environment configurations๊ณผ ๊ฐ™์€ Beanstalk ๊ตฌ์„ฑ์š”์†Œ์˜ ๋…ผ๋ฆฌ์  ์ง‘ํ•ฉ์ž…๋‹ˆ๋‹ค.
  • Elastic Beanstalk์—์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๊ฐœ๋…์ ์œผ๋กœ ํด๋”์™€ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Application version

  • Appliation version์€ ๋ ˆ์ด๋ธ”์ด ์ง€์ •๋œ ๋ฐฐํฌ ๊ฐ€๋Šฅํ•œ ์ฝ”๋“œ์˜ ๋ฌถ์Œ์ž…๋‹ˆ๋‹ค.
  • Application์—๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ Application version์ด ์žˆ์„ ์ˆ˜ ์žˆ๊ณ , ๊ฐ Application version์€ ๊ณ ์œ ํ•ฉ๋‹ˆ๋‹ค.
  • Application version์€ Application์˜ ์ผ๋ถ€์ž…๋‹ˆ๋‹ค.

Environment

  • Environment๋Š” Application version์„ ์‹คํ–‰ ์ค‘์ธ AWS ๋ฆฌ์†Œ์Šค ๋ชจ์Œ์ž…๋‹ˆ๋‹ค.
  • 1๊ฐœ์˜ Environment๋Š” 1๊ฐœ์˜ Application Version๋งŒ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ 1๊ฐœ์˜ Application Version์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ Environment์—์„œ ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • dev ํ™˜๊ฒฝ, prod ํ™˜๊ฒฝ, test ํ™˜๊ฒฝ ๋“ฑ์„ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ๋„์žˆ์Šต๋‹ˆ๋‹ค.

Environment tier

  • Environment tier๋Š” Environment์—์„œ ์‹คํ–‰ํ•˜๋Š” Application์˜ ์œ ํ˜•์„ ์ง€์ •ํ•˜๊ณ  ํ”„๋กœ๋น„์ €๋‹ํ•  ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
  • Environment tier๋Š” 2๊ฐœ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Web server environment
    • HTTP ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
  • Worker environment
    • Amazon SQS Queue์—์„œ ์ž‘์—…์„ ๊ฐ€์ ธ์™€ ์ฒ˜๋ฆฌํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Elastic Beanstalk์˜ deploy options

  • All at once
    • ๊ฐ€์žฅ ๋น ๋ฅธ ๋ฐฐํฌ ๋ฐฉ๋ฒ•์œผ๋กœ ์ƒˆ ๋ฒ„์ „์„ ๋ชจ๋“  ์ธ์Šคํ„ด์Šค์— ๋™์‹œ์— ๋ฐฐํฌํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฐฐํฌ๊ฐ€ ์ˆ˜ํ–‰๋˜๋Š” ๋™์•ˆ์—๋Š” ๋ชจ๋“  ์ธ์Šคํ„ด์Šค๊ฐ€ ์ž ์‹œ ๋™์•ˆ ์„œ๋น„์Šค๊ฐ€ ๋ถˆ๊ฐ€๋Šฅ(๋‹ค์šด ํƒ€์ž„์ด ๋ฐœ์ƒ)ํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฐฐํฌ ์ค‘์— ๋‹ค๋ฅธ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€ ๋น„์šฉ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  • Rolling
    • ์–ผ๋งˆ๋งŒํผ ์ธ์Šคํ„ด์Šค๋ฅผ ์ค‘๋‹จํ• ์ง€๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ , ์ˆœ์ฐจ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธํ•ด ๋‚˜๊ฐ€๋Š” ๋ฐฐํฌ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
    • ์–ผ๋งˆ๋งŒํผ ์ธ์Šคํ„ด์Šค๋ฅผ ์ค‘๋‹จํ• ์ง€๋ฅผ ๊ฒฐ์ •ํ•œ ๊ฒƒ์„ Batch Size์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
    • Batch size๋งŒํผ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ฐจ๋ก€๋Œ€๋กœ ๋ฐฐํฌ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด Batch size๊ฐ€ 2๋ผ๋ฉด 2๊ฐœ์”ฉ ์ˆœ์ฐจ์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ๋ฉ๋‹ˆ๋‹ค.
    • ๋ฐฐํฌ ์ค‘์— ๋‹ค๋ฅธ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€ ๋น„์šฉ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

  • Rolling with additional batches
    • Rolling์€ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ค‘๋‹จ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐํฌ ์ค‘๊ฐ„์—๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์šฉ๋Ÿ‰(capacity)๊ฐ€ ์ค„์–ด๋“ค๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
    • additional batches๋Š” ์ถ”๊ฐ€ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์šฉ๋Ÿ‰์ด ์ค„์–ด๋“ค์ง€ ์•Š๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค.
    • ๋ฐฐํฌ ์ค‘์— ์ถ”๊ฐ€ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€ ๋น„์šฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
  • Immutable
    • Immutable ์—…๋ฐ์ดํŠธ๋Š” Rolling์˜ ๋Œ€์•ˆ์ž…๋‹ˆ๋‹ค.
    • Rolling ์—…๋ฐ์ดํŠธ๋Š” ์—…๋ฐ์ดํŠธ์— ์‹คํŒจํ•˜๋ฉด Rollback ์—…๋ฐ์ดํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•˜์—ฌ ์ด์ „์˜ ์ƒํƒœ๋กœ ์ฒœ์ฒœํžˆ ๋Œ์•„๊ฐ€์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    • Immutable ์—…๋ฐ์ดํŠธ๋Š” ์ž„์‹œ ASG์™€ ์ƒ์„ฑํ•˜์—ฌ ์—…๋ฐ์ดํŠธํ•˜๋Š”๋ฐ ์—…๋ฐ์ดํŠธ์— ์‹คํŒจํ•˜๋ฉด ์ž„์‹œ ASG๋งŒ ์ข…๋ฃŒํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
    • Immutable ์—…๋ฐ์ดํŠธ๋Š” ์ž„์‹œ ASG๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋‹จ์ผ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๊ธฐ์กด์˜ ASG์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ํ•จ๊ป˜ ์„œ๋น„์Šค๋ฅผ ํ•˜๋‹ค๊ฐ€ ์ž„์‹œ ASG์˜ ๋‹จ์ผ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ •์ƒ์ด๋ผ๊ณ  ํŒ๋‹จ์ด ๋˜๋ฉด ๊ธฐ์กด ASG์˜ ์ธ์Šคํ„ด์Šค ์ˆ˜๋งŒํผ ์ž„์‹œ ASG์— ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
    • ์—…๋ฐ์ดํŠธ๋œ ๋ชจ๋“  ์ธ์Šคํ„ด์Šค์˜ ์ƒํƒœ ํ™•์ธ์ด ๋๋‚˜๋ฉด ์ž„์‹œ ASG์— ์žˆ๋Š” ๊ธฐ์กด ASG๋กœ ์˜ฎ๊ธฐ๊ณ  ์ž„์‹œ ASG๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.
    • ๋ฐฐํฌ ์ค‘์— ์ถ”๊ฐ€ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€ ๋น„์šฉ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.
  • Traffic splitting
    • ์นด๋‚˜๋ฆฌ์•„ ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
    • ์ˆ˜์‹ ๋˜๋Š” ํŠธ๋ž˜ํ”ฝ์˜ ์ผ๋ถ€๋ฅผ ์ƒˆ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฒ„์ „์œผ๋กœ ์ „ํ™˜ํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•œ ํ›„ ๊ฒ€์ฆ์ด ์™„๋ฃŒ๋˜๋ฉด ์ƒˆ ๋ฒ„์ „์œผ๋กœ ์™„์ „ํžˆ ์ „ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
    • ๊ธฐ์กด ASG ๊ทธ๋ฃน๊ณผ ๊ฐ™์€ ์šฉ๋Ÿ‰์˜ ์ž„์‹œ ASG๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํŠธ๋ž˜ํ”ฝ ๋ถ„ํ• (Traffic split)ํ•˜์—ฌ ์ƒˆ๋กœ์šด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฒ„์ „์„ ๊ฒ€์ฆํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
    • Traffic splitting ๋ฐฐํฌ์—๋Š” Application Load Balancer๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • Blue Green
    • Blue Green ๋ฐฐํฌ๋Š” ๊ธฐ์กด ํ™˜๊ฒฝ(Blue)์—์„œ ์™„์ „ํžˆ ์ƒˆ๋กœ์šด ํ™˜๊ฒฝ(Green)์„ ์ƒ์„ฑํ•œ ๋‹ค์Œ ์ „ํ™˜ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋‹ค์šดํƒ€์ž„์ด ์—†์Šต๋‹ˆ๋‹ค.
    • Green ํ™˜๊ฒฝ์— ๋Œ€ํ•œ ๊ฒ€์ฆ์ด ๋๋‚˜๋ฉด URL์„ ์ „ํ™˜ํ•ด Green ํ™˜๊ฒฝ์„ ๋ฉ”์ธ ํ™˜๊ฒฝ์œผ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.(Swap URL)

Elastic Beanstalk application version lifecycle

  • Elastic Beanstalk์— ์ƒˆ ๋ฒ„์ „์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์—…๋กœ๋“œํ•  ๋•Œ๋งˆ๋‹ค application version์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
  • ๊ธฐ๋ณธ์ ์œผ๋กœ application version quota๋Š” 1000๊ฐœ๋กœ qutoa ์ฆ์„ค์„ ์š”์ฒญํ•˜์ง€ ์•Š์œผ๋ฉด 1000๊ฐœ๊นŒ์ง€๋งŒ ์ƒ์„ฑ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
  • Application version lifecycle policy๋ฅผ ์ ์šฉํ•˜๋ฉด application version์˜ ๊ฐœ์ˆ˜๊ฐ€ quota์— ๋„๋‹ฌํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • lifecycle policy๋Š” ์˜ค๋ž˜๋œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฒ„์ „ ์‚ญ์ œ, ์ž„๊ณ„๊ฐ’์„ ์ดˆ๊ณผํ•˜๋Š” ๊ฒฝ์šฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฒ„์ „ ์‚ญ์ œํ•˜๋„๋ก ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

.ebextensions

  • Elastic Beanstalk์˜ ๊ตฌ์„ฑ ํŒŒ์ผ์„ .ebextensions์— ์ถ”๊ฐ€ํ•˜์—ฌ environment์˜ ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ ์ถ”๊ฐ€ ๋ฆฌ์†Œ์Šค(RDS, ElasticCache ๋“ฑ)์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Elastic Beanstalk์—์„œ environment๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
  • ๊ตฌ์„ฑ ํŒŒ์ผ์€ YAML ๋˜๋Š” JSON ํ˜•์‹์œผ๋กœ ํ™•์žฅ๋ช…์€ .config์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
  • .ebextensions ํด๋”์— .ebextensions/network-load-balancer.config์™€ ๊ฐ™์ด ๊ตฌ์„ฑํŒŒ์ผ์„ ์œ„์น˜์‹œํ‚ค๋ฉด ๋ฉ๋‹ˆ๋‹ค.
๋ฐ˜์‘ํ˜•