- This project shows how to run an ASP.NET Core Web API project as an AWS Lambda exposed through Amazon API Gateway.
If you liked the project, please give a star ;)
- Visual Studio 2019 or Visual Studio Code
- .Net Core 2.X
To integrate the AWS SDK for .NET with the dependency injection system built into ASP.NET Core the NuGet package AWSSDK.Extensions.NETCore.Setup is referenced. In the Startup.cs file the Amazon S3 client is added to the dependency injection framework. The S3ProxyController will get its S3 service client from there.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddAWSService<Amazon.S3.IAmazonS3>();
}
To configure this project to handle requests from an Application Load Balancer instead of API Gateway change
the base class of LambdaEntryPoint
from Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
to
Amazon.Lambda.AspNetCoreServer.ApplicationLoadBalancerFunction
.
Once you have edited your template and code you can deploy your application using the Amazon.Lambda.Tools Global Tool from the command line.
Install Amazon.Lambda.Tools Global Tools if not already installed.
dotnet tool install -g Amazon.Lambda.Tools
If already installed check if new version is available.
dotnet tool update -g Amazon.Lambda.Tools
Execute unit tests
cd "LambdaShoppingListWebAi/test/LambdaShoppingListWebAi.Tests"
dotnet test
Deploy application
cd "LambdaShoppingListWebAi/src/LambdaShoppingListWebAi"
dotnet lambda deploy-serverless