You need to target netcoreapp1.0 in order for your Web API to work on AWS Lambda. You’ll also need to reference some nuget packages from aws so replace the contents of the aws.lamda.csproj file with the following lines:

Rename Program.cs to LocalEntrypoint.cs and replace the contents of the file with the following lines:

usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Threading.Tasks;usingMicrosoft.AspNetCore.Hosting;usingMicrosoft.AspNetCore.Builder;namespace aws.lambda{/// <summary>/// The Main function can be used to run the ASP.NET Core application locally using the Kestrel webserver./// </summary>publicclass LocalEntryPoint
{publicstaticvoid Main(string[] args){var host =new WebHostBuilder().UseKestrel().UseContentRoot(Directory.GetCurrentDirectory()).UseIISIntegration().UseStartup<Startup>().Build();
host.Run();}}}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
namespace aws.lambda
{
/// <summary>
/// The Main function can be used to run the ASP.NET Core application locally using the Kestrel webserver.
/// </summary>
public class LocalEntryPoint
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}

{"Information": ["This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.","To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.","dotnet lambda help","All the command line options for the Lambda command can be specified in this file."],"profile": "default","region": "eu-west-1","configuration": "Release","framework": "netcoreapp1.0","function-runtime": "dotnetcore1.0","template": "serverless.template"}

{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "default",
"region": "eu-west-1",
"configuration": "Release",
"framework": "netcoreapp1.0",
"function-runtime": "dotnetcore1.0",
"template": "serverless.template"
}

4 thoughts on “Deploy your ASP.NET Core Web API to AWS Lambda”

First, it seems you have to create the first version by uploading to the bucket and then creating the stack from the browser using the bucket. After that everything can be done per your instruction via the command line. Not sure if I missed a step.

Second, any idea how to connect to an RDS using this example. Normally I set the IP in the whitelist in the RDS but since this is serverless the IP changes each time.