58
C# on AWS Lambda 1 @phermens

C# & AWS Lambda

Embed Size (px)

Citation preview

Page 1: C# & AWS Lambda

C# on AWS Lambda

1 @phermens

Page 2: C# & AWS Lambda

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

Page 3: C# & AWS Lambda

Every day a little more Dutch

3

Page 4: C# & AWS Lambda

A little bit of history

4 @phermens

Page 5: C# & AWS Lambda

Launched in Nov 2014.5

@phermens

Page 6: C# & AWS Lambda

C# support in Dec 2016.6

@phermens

Page 7: C# & AWS Lambda

Officially only supports .NET Core.7

@phermens

Page 8: C# & AWS Lambda

AWS was first of the “major providers”.8

@phermens

Page 9: C# & AWS Lambda

They have an open-source SDKhttps://github.com/aws/aws-sdk-net/ 9

@phermens

Page 10: C# & AWS Lambda

They also have a great ‘dotnet’ repo…https://github.com/aws/aws-lambda-dotnet/ 10

@phermens

Page 11: C# & AWS Lambda

… & most of my tooling is from here11

@phermens

Page 12: C# & AWS Lambda

It’s “Hello world” time!

12 @phermens

Page 13: C# & AWS Lambda

13 @phermens

Hello World! (including ILambdaContext)

Page 14: C# & AWS Lambda

“Relatively simple” configuration14

@phermens

Page 15: C# & AWS Lambda

Wait, we need more than code!

15 @phermens

Page 16: C# & AWS Lambda

16 @phermens

Set up an account

Page 17: C# & AWS Lambda

Install the CLI

17 @phermens

Page 18: C# & AWS Lambda

18 @phermens

Page 19: C# & AWS Lambda

19 @phermens

Regions? AZ’s?

Page 20: C# & AWS Lambda

20 @phermens

IAM?

Page 21: C# & AWS Lambda

21 @phermens

Required values can be set in code!

Page 22: C# & AWS Lambda

22 @phermens

… or on the command line!

Page 23: C# & AWS Lambda

NOW it’s “Hello world” time!

23 @phermens

Page 24: C# & AWS Lambda

24 @phermens

Hello World! (including ILambdaContext)

Page 25: C# & AWS Lambda

Deploying “Hello-World”

25 @phermens

Page 26: C# & AWS Lambda

26 @phermens

Running deploy-function & invoke-function

Page 27: C# & AWS Lambda

Calling our “Hello” function

27 @phermens

Page 28: C# & AWS Lambda

28 @phermens

We can use the ‘Amazon’ NuGet package(s)

Page 29: C# & AWS Lambda

We can use AWS SNS29

@phermens

Page 30: C# & AWS Lambda

We can use any ‘webhook’-type integration30

@phermens

Page 31: C# & AWS Lambda

Creating a “Hello-World-Caller”

31 @phermens

Page 32: C# & AWS Lambda

32 @phermens

Pretty straightforward using the SDK

Page 33: C# & AWS Lambda

Just F5 in VS Code!33

@phermens

Page 34: C# & AWS Lambda

Larger architectures?

34 @phermens

Page 35: C# & AWS Lambda

Our “infra team” had a fun exercise...35

@phermens

Page 36: C# & AWS Lambda

CloudFormation - scripted infrastructure36

@phermens

Page 37: C# & AWS Lambda

Normally looks like this...37

@phermens

Page 38: C# & AWS Lambda

… but can also look like this!38

@phermens

Page 39: C# & AWS Lambda

“Add trigger” to your Lambda39

@phermens

Page 40: C# & AWS Lambda

Pick your integration - whatever you want!40

@phermens

Page 41: C# & AWS Lambda

Or just, “deploy-serverless” with the CLI41

@phermens

Page 42: C# & AWS Lambda

AWS Serverless Application Modelhttp://github.com/awslabs/ 42

@phermens

Page 43: C# & AWS Lambda

http://serverless.com/framework/docs/ 43

@phermens

Page 44: C# & AWS Lambda

So, what does this mean for Coolblue?44

@phermens

Page 45: C# & AWS Lambda

This makes it look simple!45

@phermens

Page 46: C# & AWS Lambda

Let’s recap some “gotchas”

46 @phermens

Page 47: C# & AWS Lambda

47 @phermens

Timings can vary wildly!

Page 48: C# & AWS Lambda

Default values can bite you!48

@phermens

Page 49: C# & AWS Lambda

Know your costs! 800,000 sec = 9.25 dayshttps://aws.amazon.com/lambda/pricing/ 49

@phermens

Page 50: C# & AWS Lambda

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

Page 51: C# & AWS Lambda

‘ILambdaContext’ should ALWAYS be last51

@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'."

}

Page 52: C# & AWS Lambda

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.

Page 53: C# & AWS Lambda

Containers can be reused!https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/ 53

@phermens

Page 54: C# & AWS Lambda

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/

Page 55: C# & AWS Lambda

https://aws.amazon.com/documentation/ 55

@phermens

Page 56: C# & AWS Lambda

56 @phermens

Page 57: C# & AWS Lambda

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

Page 58: C# & AWS Lambda

Thanks!

58 @phermens