[Architecting on AWS] Serverless

Created
November 17, 2023
Created by
D
DaEun Kim
Tags
AWS
Property

Lambda

  • λžŒλ‹€ ν•¨μˆ˜ 생성에 ν•„μš”ν•œ 것.
    • ν•¨μˆ˜ 이름
    • λŸ°νƒ€μž„ (Python, JVM λ“±)
    • application code
  • λžŒλ‹€ ν”„λ‘œμ„ΈμŠ€λŠ” 항상 λ–  μžˆλŠ” 게 μ•„λ‹ˆκ³  이벀트 트리거λ₯Ό λ°›μœΌλ©΄ ν”„λ‘œμ„ΈμŠ€κ°€ λ– μ„œ μ‹€ν–‰λ˜λŠ” ꡬ쑰. (μ΅œλŒ€ 15λΆ„κΉŒμ§€ λ–  μžˆμ„ 수 μžˆλ‹€.)
  • 이벀트 트리거 μ£Όμ²΄λŠ” SNS/S3/eventbridge λ“± λ‹€μ–‘ν•˜λ‹€.
  • CPU/memory μžμ› 점유 양에 따라 μ•Œμ•„μ„œ μžμ›μ„ ν• λ‹Ήν•΄μ€€λ‹€. λŒ€μ‹  μ΅œμ†Œ/μ΅œλŒ€ λ²”μœ„λŠ” 지정 ν•„μš”.
  • recursive invocation 에 μ£Όμ˜ν•΄μ•Ό ν•œλ‹€. https://docs.aws.amazon.com/lambda/latest/dg/invocation-recursion.html
  • 이벀트 트리거 주체가 lambda 에 μ ‘κ·Όν•˜λ„λ‘ 이벀트 트리거 μ£Όμ²΄μ—κ²Œ resource-based policy λ₯Ό μžλ™μœΌλ‘œ μƒμ„±ν•œλ‹€.
  • λžŒλ‹€λ‘œ μ‹€ν–‰ν•  μ½”λ“œκ°€ λ‹€λ₯Έ μ„œλΉ„μŠ€μ— μ ‘κ·Ό κΆŒν•œμ΄ ν•„μš”ν•˜λ‹€λ©΄ λžŒλ‹€ ν•¨μˆ˜μ—κ²Œ ν•΄λ‹Ή μ„œλΉ„μŠ€ 접근에 λŒ€ν•œ role 을 λΆ€μ—¬ν•΄μ•Ό ν•œλ‹€.

API Gateway

  • lambda 으둜 λΉ„μ¦ˆλ‹ˆμŠ€λ₯Ό κ΅¬ν˜„ν•˜λ©΄ API Gateway μ—μ„œ REST API μŠ€νŽ™μ„ μ •μ˜ & λžŒλ‹€ ν•¨μˆ˜μ™€ 맀핑.
  • end-user 인증 λ‹΄λ‹Ή κ°€λŠ₯. (with Cognito)
  • API λ³„λ‘œ ν…ŒμŠ€νŠΈ 및 배포 κ°€λŠ₯.

SQS

  • 메세지 ν•˜λ‚˜ λ‹Ή μ΅œλŒ€ 256kb ν—ˆμš©.
  • μ»¨μˆ˜λ¨Έκ°€ 메세지λ₯Ό polling ν•΄μ•Ό ν•˜λŠ” ꡬ쑰.
  • Type
    • Standard
      • μˆœμ„œλ₯Ό 보μž₯ν•˜μ§€ μ•ŠμŒ
      • μ΅œμ†Œ ν•œλ²ˆ 보μž₯ (메세지λ₯Ό μ€‘λ³΅μœΌλ‘œ 가지고 μžˆμ„ 수 μžˆλ‹€.)
      • μ΄ˆλ‹Ή 호좜 νšŸμˆ˜μ— μ œν•œ μ—†μŒ.
    • FIFO
      • μˆœμ„œλ₯Ό 보μž₯함.
      • μ΅œλŒ€ ν•œλ²ˆ 보μž₯ (메세지λ₯Ό μ€‘λ³΅μœΌλ‘œ 가지고 μžˆμ§€ μ•ŠμœΌλ‚˜ λˆ„λ½ κ°€λŠ₯?)
      • μ΄ˆλ‹Ή 300λ²ˆκΉŒμ§€ 큐 호좜 ν—ˆμš©.
  • visuality timeout (κ°€μ‹œμ„± μ œν•œ μ‹œκ°„)
    • 메세지가 μ€‘λ³΅μœΌλ‘œ μ²˜λ¦¬λ˜λŠ” 것을 λ°©μ§€ν•˜λŠ” μˆ˜λ‹¨.
    • visuality timeout 을 μ„€μ • β†’ μ–΄λ–€ μ»¨μˆ˜λ¨Έκ°€ 메세지λ₯Ό ν•œλ²ˆ polling ν•˜λ©΄ ν•΄λ‹Ή νƒ€μž„μ•„μ›ƒμ΄ μ„ΈνŒ…λ˜κ³  νƒ€μž„μ•„μ›ƒ 될 λ•Œ κΉŒμ§€ λ‹€λ₯Έ μ»¨μˆ˜λ¨Έλ“€μ΄ 메세지λ₯Ό 읽어듀일 수 μ—†μŒ.
  • DLQ(Dead Letter Queue) μ˜΅μ…˜ 지원.
  • short polling & long polling https://docs.aws.amazon.com/en_en/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-short-and-long-polling.html

SNS

  • service that fans out messages to multiple consumers.
  • SNS κ°€ μ»¨μˆ˜λ¨Έμ—κ²Œ 메세지λ₯Ό push ν•˜λŠ” ꡬ쑰.
  • FIFO μ˜΅μ…˜ κ°€λŠ₯.

Step Function

  • service that orchestrates workflow with multiple steps.
  • 단계 ν•˜λ‚˜ = state
  • state 에도 μ—¬λŸ¬ νƒ€μž…μ΄ μžˆλ‹€.
    • pass
    • task
    • …
  • μ—¬λŸ¬ state λ₯Ό μ •μ˜ν•˜κ³  각 state μ—μ„œ μˆ˜ν–‰ν•  νƒœμŠ€ν¬λ₯Ό λžŒλ‹€ ν•¨μˆ˜λ‘œ μ •μ˜ κ°€λŠ₯.
  • JSON 으둜 states μž‘μ„± κ°€λŠ₯.