Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bilzard/20f8eed33ef49a980cfb24c0bc7d6870 to your computer and use it in GitHub Desktop.
Save bilzard/20f8eed33ef49a980cfb24c0bc7d6870 to your computer and use it in GitHub Desktop.
Anti-patterns & Best Practices in AWS Lambda

Note: AWS blackbelt online seminar - part3

Anti-patterns & Best Practices in AWS Lambda

Speaker: 西谷 圭介, AWS Japan

  • The only tunable parameter is MEMORY, but, in fact, it affects all computing resources ex. CPU usage
  • Reduce package size
    • using client library
      • ex) Uglify.js
  • Do NOT use VPCs
    • 10-30 additional latencies for attachng ENIs
  • 1 lambda function : 1 responsibility
  • Separate handler code and busines logics
    • keep your business logic testabile
  • Initialize in global scope
    • resources allocated in global scope is REUSED by another execution (if it's warm-start context)
  • Do not write orchestration code in your function
    • easy to cause timeout
    • use AWS Step Functions instead
  • In error handling...
    • Set timeouts for external services
      • ex) HTTP, Redis, DynamoDB
      • if lambda function timeouts before external service calls timeouts, no logs output
      • Retry invokations
        • use exponential backoff with jitter
  • Do not use pre-installed SDKs
    • AWS periodically updates them
      • it may affect your code
  • Use asyncronous invokation instead of syncronous invokation
  • Keep idempotency for yourself
    • lambda may executes multiple times
  • Do not hard-code
    • sepalate logics and configulations
      • easy to switch environments
      • reduce security risks
    • store configuration in managed services
      • System Manager - Paramteter Store (Free of charge)
      • Secret Manager (charges)
  • Do not use RDB
    • hundreds & thousands of concurrent executions of Lambda Functions may exceeds max connection limits of RDB
    • VPC coldstart is unavoidable
  • Use scalable database ex. Dynamo DB instead
    • connections scaleout
    • no VPC coldstart
    • throughputs also scaleout
  • If you have to use RDB ...
    • control max concurrecy limit
  • Do not use fixed IP addresses
    • VPC coldstart
    • ENI becomes single point of failure
  • Allow minimum necessary permitions as possible
  • If you test lambda function code ...
    • run unittext on your local machine
    • run integration test on actural managed services
      • maintaining mocks and stabs costs high
    • run test on pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment