Successfully reported this slideshow.
Your SlideShare is downloading. ×

Surviving Serverless Testing: The ultimate Guide

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 81 Ad

Surviving Serverless Testing: The ultimate Guide

Download to read offline

Even if a Serverless Function is small by design, testing it business logic and integration with other cloud components is kind of hard. Good to have a "Survival Guide".

Even if a Serverless Function is small by design, testing it business logic and integration with other cloud components is kind of hard. Good to have a "Survival Guide".

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Similar to Surviving Serverless Testing: The ultimate Guide (20)

Advertisement

More from open knowledge GmbH (20)

Advertisement

Surviving Serverless Testing: The ultimate Guide

  1. 1. The utlimate SERVERLESS TESTING GUIDE #WISSENTEILEN THE PRACTICAL SKILLS YOU‘LL NEED TO TEST SERVERLESS by Lars Röwekamp a.k.a @mobileLarson
  2. 2. ABOUT OPEN KNOWLEDGE Software development and IT consulting
  3. 3. ABOUT ME Who am i? • CIO New Technologies • Enterprise & Mobile • Author, Speaker, Coach & Mentor • Snowboard & MTB Enthusiast • Traveller between the worlds Lars Röwekamp (a.k.a. @mobileLarson) LR
  4. 4. Testing Serverless
  5. 5. Shouldn‘t be to complicated!- famous last words -
  6. 6. Testing is about … gaining confidence in your code running as expected on a specific target platform.
  7. 7. Testing is about … minimizing the risk that something unexpected will happen in production.
  8. 8. „What does this mean in the context of Serverless?"
  9. 9. „Run Code, not Servers!“
  10. 10. #WISSENTEILEN “Run your business code highly-available in the cloud in response to events and scale without any servers to manage.“* *(AWS Lambda product description)
  11. 11. #WISSENTEILEN “Run your business code highly distributed and event driven in a non transparent environment with no single point of control.“* *(my personal interpretation)
  12. 12. The Road to the Cloud ... The Serverless Showcase
  13. 13. AWS Cloud Use-Case: Upload Image upload image with additional information
  14. 14. AWS Cloud Store raw Image 1 Use-Case: Upload Image upload image with additional information
  15. 15. AWS Cloud Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  16. 16. AWS Cloud AWS Step Functions workflow: Store Image Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  17. 17. AWS Cloud AWS Step Functions workflow: Store Image Create ThumbnailStore raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  18. 18. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  19. 19. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  20. 20. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  21. 21. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  22. 22. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  23. 23. „What can go wrong?“
  24. 24. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  25. 25. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  26. 26. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  27. 27. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  28. 28. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  29. 29. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  30. 30. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  31. 31. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  32. 32. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  33. 33. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  34. 34. What could possibly go wrong? • internal programming /business logic errors • abnormalities (e.g. unexpected or invalid calls) • lost or duplicated events • high latency / timeouts • security attacks (e.g. DoS/DDoS) • personalized SLAs / usage plans / unexpected peaks of workload • customer location changes • …
  35. 35. „Run Code, not Servers“, they said! „It will be fun“, they said
  36. 36. What, how and where should we test to … • gain confidence in our code • minimize risk of failures in production
  37. 37. Testing, the traditional way
  38. 38. Testing, the serverless way „The biggest complexity is not within the function itself, but in how it interacts with other functions and services (a.k.a. cloud components).“
  39. 39. Testing, the serverless way Remember goals of testing: „minimize risk“ • configuration risk • technical workflow risk • business logic risk • integration risk
  40. 40. Testing, the serverless way Remember goals of testing: „minimize risk“ • configuration risk • technical workflow risk • business logic risk • integration risk
  41. 41. Testing, the serverless way
  42. 42. Unit Testing … for Serverless Functions „Make sure that your business logic is working as expected.“ • business logic errors • coding errors • …
  43. 43. Unit Testing … for Serverless Functions • seperation of logic and infrastructure • mock dependencies • jUnit, testNG, Mockito • Jasmin, MochaJS, JEST
  44. 44. Integration Testing … for Cloud Components „Make sure that the integration of your serverless function with all the other cloud components works as expected.“ • wrong DynamoDB query • unexpected response format • ….
  45. 45. Integration Testing … for Cloud Components • dev/test components in the cloud* • mock/fake cloud components** • S3rver • dynamodb-local • kinesalite • node-lambda • fake-sns • elasticmq* could become kind of expensive ** potential problem of self fulfilling prophecy
  46. 46. End-to-End Testing … for User-Stories „Make sure that chains of serverless functions and cloud components work as expected - inside the target environment.“ • wrong IAM permissions • timeouts not set correctly • not enough memory allocated
  47. 47. End-to-End Testing … for User-Stories • cloud test stages* • local cloud emulation** • SAM local (AWS) • LocalStack (localstack.org) • Serverless Offline (Serverless Framework)* could become kind of expensive ** emulate only part of the real world restrictions
  48. 48. Best Practices
  49. 49. #1 seperate business logic from infrastructure inside your functions Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate u
  50. 50. Infrastructure Business Logic
  51. 51. Infrastructure Business Logic
  52. 52. Business Logic Tests
  53. 53. #2 mock cloud infrastructure components of your functions Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate u um
  54. 54. Infrastructure
  55. 55. AWS agnostic logger (log4j2)
  56. 56. fake infrastructure component (Context)
  57. 57. mock infrastructure component (Context)
  58. 58. #3 use local environment for functional testing (e.g. SAM local) Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate uvia SAM local via SAM local SAM yaml TEST u u
  59. 59. $ sam local invoke "Greetings" -e event-greeting.json --env-vars env.json function name payload for function
  60. 60. $ sam local invoke "Greetings" -e event-greeting.json --env-vars env.json function name payload for function
  61. 61. #WISSENTEILEN #4 use local environment for trigger integration testing Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate uvia SAM local via SAM local SAM yaml TEST u u i i
  62. 62. $ sam local start-api –p 8080
  63. 63. $ sam local start-api –p 8080
  64. 64. $ sam local start-api –p 8080
  65. 65. #WISSENTEILEN #5 use local „cloud“ components for basic integration testing Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate u via DynamoDB local via FakeS3 via SAM local via SAM local SAM yaml TEST u u i i i i WARNING: local cloud components can only proof functional correctness but not infrastructural correctness like DLQs, timeouts, throttling, SLAs, …
  66. 66. $ sam local generate-event [SERVICE] [OPTION] Simulate Component Event to trigger Lambda
  67. 67. $ sam local genarte-event [SERVICE] [OPTION] Simulate Component Event to trigger Lambda
  68. 68. Simulate Component triggered by Lambda $ aws –endpoint-url=http://localhost:8000 dynamodb list-tables $ java –jar DynamoDBLocal.-jar
  69. 69. Simulate Component triggered by Lambda $ aws –endpoint-url=http://localhost:8000 dynamodb list-tables
  70. 70. Simulate Component triggered by Lambda $ aws –endpoint-url=http://localhost:8000 dynamodb list-tables
  71. 71. #WISSENTEILEN #6 use temporary integration cloud for partial integration testing Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate uvia SAM local via SAM local SAM yaml TEST u u via DynamoDB local via FakeS3 i i Temorary Intregration #Dev1 ii INT i i
  72. 72. #WISSENTEILEN #7 use permanent integration cloud for end-to-end testing Testing Best Practices AWS CloudOn-Premise handler logic unit test candidate e i u integration test candidate end-to-end test candidate uvia SAM local via SAM local SAM yaml TEST u u via DynamoDB local via FakeS3 i i Permament IntregrationINT e e e e i i
  73. 73. „Are we done?“
  74. 74. #WISSENTEILEN
  75. 75. Testing in Production Remember goals of testing: „gain confidence“ • outages of cloud & cloud components • outages of 3rd party apps you depend on • bugs / problems related to scale
  76. 76. Testing in Production Robust monitoring and error reporting • logging • tracing • metrics • alerting Anticipation of disruption and automated recovery!
  77. 77. Testing in Production Chaos Engineering • Inject small doses of failure into your system!
  78. 78. seperate business logic from infrastructure inside your functions mock cloud infrastructure components of your functions use local environment for functional testing (e.g. SAM local) use local environment for trigger integration testing use local „cloud“ components for basic integration testing use temporary integration cloud for partial integration testing use permanent integration cloud for end-to-end testing REMEBER: Testing does not end in production! Testing Summary unit test e i u integration test end-to-end test e i i i u u i
  79. 79. Testing does not end in production!

×