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

Going Serverless: Tips & tricks for developing a serverless cloud app

Going Serverless: Tips & tricks for developing a serverless cloud app

Are you planning to develop a new cloud app? If so, serverless might be the right fit for you!

Serverless makes it possible to write small functions and platform providers like AWS are taking care about the deployment and scalability. However, this new concept comes with its own drawbacks when used in production, e.g. long startup times or scaling limitations.

Hence, we will show you what it takes to run a cloud app using a serverless architecture based on AWS Lambda. We will go beyond the basics to show best practices and explain why serverless might be a good fit for you. You'll learn which setup options you have for your development and deployment environment, how to develop solid serverless functions and where the limits are.

Using these learnings you'll know how you can easily scale your app for a growing number of users and be successful on the marketplace.

Links from the slides:
https://bit.ly/debugging-lambda-dotnet
https://bit.ly/test-lambda-functions
https://bit.ly/aws-appsync-blog
https://bit.ly/lambda-triggers
https://bit.ly/secure-aws-lambda
https://bit.ly/migrating-to-lambda
https://bit.ly/caching-in-lambda

023594dc361cab87c8e40d03ba0f3b18?s=128

sebastianhesse

April 08, 2019
Tweet

Transcript

  1. None
  2. Going Serverless Sebastian Hesse · K15t · @seeebiii Tips &

    tricks for developing a serverless cloud app
  3. Work on the same issue data, in different projects, on

    different Jira instances. Keeping your data in sync Backbone Issue Sync for Jira
  4. About Serverless

  5. Our Use Cases Scheduled Tasks Long Running Tasks Webhooks

  6. Typical Cloud Architecture Serverless Architecture

  7. Our Cloud Setup Other Services AWS Lambda Amazon Web Services

  8. AWS Lambda </>

  9. AWS Lambda module.exports = function (event, context, cb) { cb(null,

    "Hello World"); } </>
  10. Event-based Architecture

  11. Development Setup

  12. Local Execute, test and debug your code on your local

    machine. Cloud Upload your code to the cloud and execute it there. Development
  13. Local Cloud - Serverless Framework - Serverless Application Model (SAM)

    with
 SAM CLI - LocalStack - AWS Cloud9 - Upload & execute - No debugging possible* * bit.ly/debugging-lambda-dotnet
  14. Considerations Tests You should always write tests which can already

    identify bugs. Quick Updates Local code updates are faster. But you can optimize your cloud code updates. Real Environment Local code execution always needs to simplify something: services, access policies or more. bit.ly/test-lambda-functions
  15. Start Coding!

  16. Manually managing Lambda functions is a pain.

  17. Infrastructure as Code Use a tool to describe your infrastructure

    as code. This helps you to keep track of all your Lambda functions. CI/CD Pipeline Automate your deployment as much as possible. Use tools like Bitbucket Pipelines, AWS CodePipeline or similar. Deployment
  18. Versioning Not all customers update your app at the same

    time. Be prepared! Preprocess your app descriptor. "webhooks": [ { "event": "jira:issue_updated", "url": "/webhook?v={{version}}" } ]
  19. Best Practices

  20. Best Practices Function Scope 1.

  21. Example Tasks Further Processing Sync Content Receive Webhooks

  22. “Keep it simple, stupid.”

  23. Focus Focus on one task and do it well. Reusability

    Reuse functions within your app. Performance Keep a high performance, because every millisecond costs you money. Considerations
  24. Response Times Response Time in ms 0 250 500 750

    1000 # Request 1 2 3 4 5 Cold Start Function is "warm"
  25. Response Times Response Time in ms 0 250 500 750

    1000 # Request 1 2 3 4 5 Cold Start Function is "warm"
  26. The bigger your artifact, the slower
 the startup time*.

  27. Which programming language can I use?

  28. All programming languages can be used.

  29. Can I use framework X ?

  30. No! Keep your function size as small as possible.

  31. Can I use AWS Lambda as a REST API?

  32. No! If you are concerned about response times.

  33. Response Times Response Time in ms 0 250 500 750

    1000 # Request 1 2 3 4 5 Cold Start is always there!
  34. API Gateway Built resilient APIs backed by Lambda functions. AWS

    AppSync Build your own serverless backend using AWS AppSync which is powered by GraphQL. Serverless REST API bit.ly/aws-appsync-blog
  35. Best Practices Communication 2.

  36. Synchronous Communication

  37. Synchronous Communication

  38. Synchronous Communication

  39. S3 Bucket Synchronous Communication

  40. S3 Bucket API Gateway DynamoDB SQS Asynchronous Communication

  41. bit.ly/lambda-triggers Asynchronous Communication

  42. bit.ly/lambda-triggers Asynchronous Communication

  43. Best Practices Scalability 3.

  44. Lambda Functions are scaled automatically, right?

  45. 1000 webhooks at the same time is no exception.

  46. Yes No Other services are not necessarily scaled. Lambda Functions

    are scaled by AWS.
  47. Problem: Scaling

  48. Problem: Scaling

  49. Solution: Buffer Requests Kinesis

  50. Best Practices Execution Management 4.

  51. 15 minutes execution time limit.

  52. 15 minutes are enough for my use case.

  53. Really? How can you be sure?

  54. - Retrieve data: 350 ms - Process data: 300 ms

    - Update data: 350 ms Example: Synchronize 1000 Issues 1 sec / issue => ~16 min.
  55. Recursion Before timing out, store current state and call yourself

    again. Best Practices
  56. Lambda Recursion module.exports = function(e, ctx, cb) { while (ctx.getRemainingTimeInMillis()

    > 1000) { // do something } // store state & call yourself again } 1.) Same instance problem 2.) Threshold uncertainty
  57. Outsource Move bigger workloads to EC2 or other services. Best

    Practices Recursion Before timing out, store current state and call yourself again.
  58. Serverless by managing servers? Without me!

  59. Step Functions Manage the execution workflow and work around the

    time limit. Outsource Move bigger workloads to EC2 or other services. Best Practices Recursion Before timing out, store current state and call yourself again.
  60. Step Functions Example { "StartAt": "Wait for Timestamp", "States": {

    "Wait for Timestamp": { "Type": "Wait", "SecondsPath": "$.seconds", "Next": "Send SNS Message" }, "Send SNS Message": { "Type": "Task", "Resource": "$LAMBDA_ARN", "Retry":[...], "End": true } } }
  61. Best Practices Limits 5.

  62. 3 GB available for memory allocation.

  63. Memory allocation and CPU power correlate.

  64. 50 MB Maximum artifact size for zipped files.

  65. Improve your dependency management.

  66. 512 MB available for temporary, local storage.

  67. Everything else goes into other storage services.

  68. Best Practices Maintenance 6.

  69. Clean Up Clean up data or make sure your data

    is still up-to-date. Log Collection Collect CloudWatch logs and store them somewhere else, e.g. in a file on S3. Monitoring Do health checks of your own services and send alarms to Slack. Maintenance
  70. Examples - Shut down resources in your developer stacks -

    Clean up Lambda log groups - Analyze logs for keywords
  71. Looking Ahead

  72. Security bit.ly/secure-aws-lambda Legacy Code bit.ly/migrating-to-lambda Caching bit.ly/caching-in-lambda Further Topics

  73. Serverless + Services =

  74. None
  75. Focus Keep your functions small. Find a good use case

    for your function. Scale Automatic scalability needs responsibility. Be Flexible Expand your functions as necessary. Takeaways
  76. Subtitle Scale beyond. Sebastian Hesse · K15t · @seeebiii