Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Efficient patterns for serverless development (...

Yan Cui
April 30, 2024

Efficient patterns for serverless development (AWS Summit London)

Serverless is a very different paradigm from how we used to build software, and many people are struggling with the shift in mindset and approach.

But serverless doesn't have to be hard. Once you figure out the "how", it'd be like getting a superpower, you will be able to do much more with less time and effort and build better software faster.

Yan has run serverless workloads in production since 2016 and has made all the mistakes so you don't have to. He's going to show us what works and what doesn't.

He will walk us through a day in the life of a serverless developer, showing you how to write and test serverless applications, advanced architectural patterns and best practices for building scalable, secure and cost-efficient applications in the cloud.

Yan Cui

April 30, 2024
Tweet

More Decks by Yan Cui

Other Decks in Technology

Transcript

  1. An architectural pattern for creating loosely-coupled application components that can

    easily connect to their environment via ports and adapters.
  2. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  3. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  4. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  5. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  6. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  7. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  8. Port Port Port Port Adapter Adapter Lambda Adapter Client B

    Adapter External system Adapter Application Core Domain External system External system
  9. Port Port Port Port Adapter Adapter Lambda Adapter Client B

    Adapter External system Adapter Application Core Domain External system External system (event, context) CreateUserCommand
  10. Port Port Port Port Adapter Adapter Lambda Adapter Client B

    Adapter External system Adapter Application Core Domain External system External system
  11. Port Port Port Port Adapter Adapter Lambda Adapter Fargate Adapter

    External system Adapter Application Core Domain External system External system
  12. Creates portability that is useful when you’re not sure if

    a workload should run in Lambda or container
  13. Port Port Port Port Adapter Adapter Lambda Adapter Fargate Adapter

    External system Adapter Application Core Domain External system External system
  14. Port Port Port Port Adapter Adapter Lambda Adapter Fargate Adapter

    External system Adapter Application Core Domain External system DynamoDB
  15. Port Port Port Port Adapter Adapter Lambda Adapter Fargate Adapter

    External system Adapter Application Core Domain External system Mock
  16. Port Port Port Port Adapter Adapter Lambda Adapter Fargate Adapter

    External system Adapter Application Core Domain External system RDS
  17. Port Port Port Port Adapter Adapter Client A Adapter Client

    B Adapter External system Adapter Application Core Domain External system External system
  18. Serverless means: 1. No need to manage servers. 2. Scale

    to zero. 3. Usage-based pricing with no minimum.
  19. Option 1: Hexagonal Architecture Universally applicable (language, framework, etc.) Can’t

    test direct integrations Portability Upfront work to create abstraction layers
  20. Option 2: Local simulation Not only Lambda. Never 100% accurate

    - missing APIs, bugs, behaviour di ff erences, etc.
  21. Option 3: Lambdalith Familiar to developers Can’t test direct integrations

    Portability Cold start penalty with large web framework dependency
  22. Option 3: Lambdalith Familiar to developers Can’t test direct integrations

    Portability Cold start penalty with large web framework dependency Might not work as well for non-API workloads
  23. Option 3: Lambdalith Familiar to developers Can’t test direct integrations

    Portability Cold start penalty with large web framework dependency Might not work as well for non-API workloads Less granular alerting and access controls
  24. Option 4: Deployment frameworks Framework does the heavy lifting for

    you Framework (and sometimes language) speci fi c
  25. Option 4: Deployment frameworks Framework does the heavy lifting for

    you Framework (and sometimes language) speci fi c Can’t test direct integrations
  26. Option 4: Deployment frameworks Framework does the heavy lifting for

    you Framework (and sometimes language) speci fi c Can’t test direct integrations Exploratory testing is NOT the same as automated tests
  27. Expectations/ Assumptions are sometimes wrong… Reality! Test against mocks Test

    against real thing “does it work?” “does it do what I expect?”
  28. Local testing Runs code locally Can use debugger Change code

    without deployment Limited coverage Prone to false positives FAST FEEDBACK! LOW CONFIDENCE
  29. Your job is to ensure all of it works Your

    application consists of more than just your code
  30. Local testing Runs code locally Can use debugger Change code

    without deployment Limited coverage Prone to false positives FAST FEEDBACK! LOW CONFIDENCE HIGH CONFIDENCE! Remote testing Test in the cloud Realistic tests Better coverage
  31. Local testing Runs code locally Can use debugger Change code

    without deployment Limited coverage Prone to false positives FAST FEEDBACK! LOW CONFIDENCE Slow deployments Every change needs deploying… SLOW FEEDBACK… HIGH CONFIDENCE! Remote testing Test in the cloud Realistic tests Better coverage
  32. Runs code locally, talk to real AWS services REMOCAL testing

    Can use debugger Change code without deployment Realistic tests
  33. Cognito API Gateway AppSync EventBridge IAM, event pattern, etc. IAM,

    URL path, method, etc. IAM, resolver con fi g, resolver template, etc.
  34. Auth Cognito AWS_IAM API Key Lambda authorizer Request validation Request

    transform Integration Lambda Direct service integration Domain logic Integrations Response transform IAM
  35. Auth Cognito AWS_IAM API Key Lambda authorizer Request validation Request

    transform Integration Lambda Direct service integration Domain logic Integrations Response transform IAM Unit Test Remocal Test E2E Test
  36. Auth Cognito AWS_IAM API Key Lambda authorizer Request validation Request

    transform Integration Lambda Direct service integration Domain logic Integrations Response transform IAM Unit Test Remocal Test E2E Test E2E Test E2E Test E2E Test E2E Test
  37. Auth Cognito AWS_IAM API Key Lambda authorizer Request validation Request

    transform Integration Lambda Direct service integration Domain logic Integrations Response transform IAM Unit Test Remocal Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test
  38. Auth Cognito AWS_IAM API Key Lambda authorizer Request validation Request

    transform Integration Lambda Direct service integration Domain logic Integrations Response transform IAM Unit Test Remocal Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test Unit Test
  39. Auth Cognito AWS_IAM API Key Lambda authorizer Request validation Request

    transform Integration Lambda Direct service integration Domain logic Integrations Response transform IAM Unit Test Remocal Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test E2E Test Unit Test Remocal Test
  40. REMOCAL testing AWS resources need to be provisioned Runs code

    locally, talk to real AWS services Can use debugger Change code without deployment Realistic tests
  41. Option 1: Hexagonal Architecture Option 2: Local simulation Option 3:

    Lambdalith Option 4: Deployment frameworks Option 5: Remocal testing
  42. productionreadyserverless.com Join 20+ AWS Heroes & Community Builders and 1000+

    happy students in levelling up your serverless game.
  43. “You could spend tens of thousands on costly mistakes, and

    years of dev time to learn these lessons, or you could spend a few days downloading Yan's extensive experience. The choice is clear!”