【问题标题】:How to Deploy dotnet core functions using the Serverless Framework?如何使用无服务器框架部署 dotnet 核心功能?
【发布时间】:2019-08-31 05:12:00
【问题描述】:
【问题讨论】:
标签:
amazon-web-services
.net-core
aws-lambda
serverless-framework
serverless
【解决方案1】:
我终于能够克服我的问题。
- cd 到 .csproj 文件夹
dotnet restore
-
dotnet lambda package 使用 dotnet lambda 工具 dotnet tool install -g Amazon.Lambda.Tools
- 假设您的 serverless.ymal 的其余部分设置正确,请确保您的 serverless.yml 具有包属性,其中包含指向 dotnet lambda 包生成的 .zip 文件的工件,例如:
package:
artifact: ./<projectFolderName>/src/<projectName>/bin/Release/netcoreapp2.1/<zipFileName>.zip
- 您需要一个使用 Startup 类的 Lambda 入口点类(例如 LambdaEntryPoint.cs):
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
除了互联网上现成的内容之外,这些步骤突出了我必须克服的一些障碍才能使我的工作正常。