All things we need to deploy .NET 5 AWS Lambda Support with Container Images!
AWS provides many resources about Lambda function and how to run it with .NET. However, I see it is quite obsolete and not very clear enough for newcomers. That's why I create this place to put all things I have gone through.
- Lambda.Dotnet
- A very simple project that we can write code and deploy it on AWS Lambda
- Lambda.Dotnet.Mediator
- Similar to
Lambda.Dotnet
. However, this project has an implementation ofMediatR
- Similar to
- Lambda.Tests
- Help us to test the function locally before deploying to AWS Lambda
We use appsetting.json
as a normal .NET application. During testing time, we can manipulate Environment Variables via Environment.SetEnvironmentVariable
Currently, we use .NET 5 for the whole solution but we still can change it to any other .NET version. We even can build a custom Docker image as well.
- In
Dockerfile
, we haveCOPY ["nuget.config", "."]
to support a private package repository. - In case you need to run the code with
.NET 6
which is not supported yet by AWS. Please let me know.
We need to create a Lambda function
with the Container image
option.
- Container image, it is a lambda function option to create a function that allows running Docker in it
To let the Lambda function know which .NET function needs to be called when the lambda function event occurred, we have to correct ENTRYPOINT
by updating CMD
:
-
FunctionHandler
Lambda.Dotnet::Lambda.Dotnet.Program::FunctionHandler
Lambda.Dotnet.Mediator::Lambda.Dotnet.Mediator.Program::FunctionHandler
-
ScheduledEventHandler
Lambda.Dotnet::Lambda.Dotnet.Program::ScheduledEventHandler
Lambda.Dotnet.Mediator::Lambda.Dotnet.Mediator.Program::ScheduledEventHandler
-
ApiGatewateHandler
Lambda.Dotnet::Lambda.Dotnet.Program::ApiGatewateHandler
Lambda.Dotnet.Mediator::Lambda.Dotnet.Mediator.Program::ApiGatewateHandler
There are some other resources from AWS that you might want to check out