Reputation: 1131
I am finding it a challenge to properly package and deploy dotnet functions (using dotnet core 2.1 runtime) utilizing Serverless to AWS Lambda. I am not finding any examples other than ones that use the SAM and dotnet deploy lambda-serverless commands.
Example: How do you package up a visual studio aws serverless project?
Using command line and Serverless, what needs to be done to properly deploy a dotnet core function to AWS Lambda? Is this even possible using the Serverless Framework?
Upvotes: 0
Views: 692
Reputation: 1131
I was finally able to overcome my issues.
dotnet restore
dotnet lambda package
using dotnet lambda tools dotnet tool install -g Amazon.Lambda.Tools
package:
artifact: ./<projectFolderName>/src/<projectName>/bin/Release/netcoreapp2.1/<zipFileName>.zip
LambdaEntryPoint.cs example
using Microsoft.AspNetCore.Hosting;
namespace MyNameSpace
{
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder.UseStartup<Startup>();
}
...
}
Startup.cs example
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
public class Startup
{
private readonly IConfiguration _configuration;
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
/// </summary>
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
}
}
Note: some of this can be generated from templates.
sls deploy
Outside of what is readily available on the Internet, these steps highlight some of the hurdles I had to overcome to get mine working.
Upvotes: 1