我发现利用Serverless到AWS Lambda正确打包和部署dotnet功能(使用dotnet core 2.1运行时)是一项挑战。除了那些使用SAM和dotnet部署lambda-serverless命令的示例之外,我没有找到任何示例。
示例:How do you package up a visual studio aws serverless project?
使用命令行和无服务器,需要做些什么才能将dotnet核心功能正确部署到AWS Lambda?使用无服务器框架甚至可以实现这一点吗?
我终于能够克服我的问题了。
dotnet restore
dotnet lambda package
使用dotnet lambda工具dotnet tool install -g Amazon.Lambda.Tools
package:
artifact: ./<projectFolderName>/src/<projectName>/bin/Release/netcoreapp2.1/<zipFileName>.zip
LambdaEntryPoint.cs示例
using Microsoft.AspNetCore.Hosting;
namespace MyNameSpace
{
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder.UseStartup<Startup>();
}
...
}
Startup.cs示例
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)
{
}
}
注意:其中一些可以从模板生成。
sls deploy
除了互联网上现有的内容之外,这些步骤突出了我必须克服的一些障碍才能使我的工作。