Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

C# & AWS Lambda

269 views

Published on

These are the slides I used at the #amsterdamdotnet meetup on 2017-03-08.

For the matching (very simple) codebases:
https://github.com/PHeonix25/lambda-helloworld &
https://github.com/PHeonix25/lambda-helloworldcaller

Published in: Technology
  • Be the first to comment

  • Be the first to like this

C# & AWS Lambda

  1. 1. C# on AWS Lambda 1 @phermens
  2. 2. About me Pat Hermens ● Father of two ● Based in Rotterdam ● Lead Developer at Coolblue ● Still have a soft-spot for VB6 https://hermens.com.au/ 2 @phermens
  3. 3. Every day a little more Dutch 3
  4. 4. A little bit of history 4 @phermens
  5. 5. Launched in Nov 2014. 5 @phermens
  6. 6. C# support in Dec 2016. 6 @phermens
  7. 7. Officially only supports .NET Core. 7 @phermens
  8. 8. AWS was first of the “major providers”. 8 @phermens
  9. 9. They have an open-source SDK https://github.com/aws/aws-sdk-net/ 9 @phermens
  10. 10. They also have a great ‘dotnet’ repo… https://github.com/aws/aws-lambda-dotnet/ 10 @phermens
  11. 11. … & most of my tooling is from here 11 @phermens
  12. 12. It’s “Hello world” time! 12 @phermens
  13. 13. 13 @phermens Hello World! (including ILambdaContext)
  14. 14. “Relatively simple” configuration 14 @phermens
  15. 15. Wait, we need more than code! 15 @phermens
  16. 16. 16 @phermens Set up an account
  17. 17. Install the CLI 17 @phermens
  18. 18. 18 @phermens
  19. 19. 19 @phermens Regions? AZ’s?
  20. 20. 20 @phermens IAM?
  21. 21. 21 @phermens Required values can be set in code!
  22. 22. 22 @phermens … or on the command line!
  23. 23. NOW it’s “Hello world” time! 23 @phermens
  24. 24. 24 @phermens Hello World! (including ILambdaContext)
  25. 25. Deploying “Hello-World” 25 @phermens
  26. 26. 26 @phermens Running deploy-function & invoke-function
  27. 27. Calling our “Hello” function 27 @phermens
  28. 28. 28 @phermens We can use the ‘Amazon’ NuGet package(s)
  29. 29. We can use AWS SNS 29 @phermens
  30. 30. We can use any ‘webhook’-type integration 30 @phermens
  31. 31. Creating a “Hello-World-Caller” 31 @phermens
  32. 32. 32 @phermens Pretty straightforward using the SDK
  33. 33. Just F5 in VS Code! 33 @phermens
  34. 34. Larger architectures? 34 @phermens
  35. 35. Our “infra team” had a fun exercise... 35 @phermens
  36. 36. CloudFormation - scripted infrastructure 36 @phermens
  37. 37. Normally looks like this... 37 @phermens
  38. 38. … but can also look like this! 38 @phermens
  39. 39. “Add trigger” to your Lambda 39 @phermens
  40. 40. Pick your integration - whatever you want! 40 @phermens
  41. 41. Or just, “deploy-serverless” with the CLI 41 @phermens
  42. 42. AWS Serverless Application Model http://github.com/awslabs/ 42 @phermens
  43. 43. http://serverless.com/framework/docs/ 43 @phermens
  44. 44. So, what does this mean for Coolblue? 44 @phermens
  45. 45. This makes it look simple! 45 @phermens
  46. 46. Let’s recap some “gotchas” 46 @phermens
  47. 47. 47 @phermens Timings can vary wildly!
  48. 48. Default values can bite you! 48 @phermens
  49. 49. Know your costs! 800,000 sec = 9.25 days https://aws.amazon.com/lambda/pricing/ 49 @phermens
  50. 50. Almost everything is case-sensitive! 50 @phermens PS> dotnet lambda deploy-function HelloWorld-EUWest # New Lambda function created PS> dotnet lambda invoke-function helloworld-euwest -p "Pat" # Error invoking Lambda function: Function not found: arn:aws:lambda:eu-west-1:955206359773:function:helloworld-euwest
  51. 51. ‘ILambdaContext’ should ALWAYS be last 51 @phermens public string SayHi(ILambdaContext context, string name = "World") { // … do something } RESPONSE: (only on invocation, after deployment) { "errorType": "LambdaException", "errorMessage": "Method 'SayHi' of type 'MyFirstLambdaFunction.HelloWorld' is not supported: the method has 2 parameters, but the second parameter is not of type 'Amazon.Lambda.Core.ILambdaContext'." }
  52. 52. Read the FAQ’s! https://aws.amazon.com/lambda/faqs/ 52 @phermens Q: How are compute resources assigned to an AWS Lambda function? In the AWS Lambda resource model, you choose the amount of memory you want for your function, and are allocated proportional CPU power and other resources. For example, choosing 256MB of memory allocates approximately twice as much CPU power to your Lambda function as requesting 128MB of memory and half as much CPU power as choosing 512MB of memory. You can set your memory in 64MB increments from 128MB to 1.5GB.
  53. 53. Containers can be reused! https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/ 53 @phermens
  54. 54. Handy links 54 @phermens Tooling ● https://github.com/aws/aws-sdk-net/ ● https://github.com/aws/aws-lambda-dotnet/ Documentation ● http://github.com/awslabs/ ● http://serverless.com/framework/docs/ ● https://aws.amazon.com/lambda/faqs/
  55. 55. https://aws.amazon.com/documentation/ 55 @phermens
  56. 56. 56 @phermens
  57. 57. Thanks! 57 @phermens Tonight’s demos are on GitHub (but they’re really nothing special!) ● https://github.com/pheonix25/lambda-helloworld ● https://github.com/pheonix25/lambda-helloworldcaller
  58. 58. Thanks! 58 @phermens

×