【问题标题】:How to Deploy dotnet core functions using the Serverless Framework?如何使用无服务器框架部署 dotnet 核心功能?
【发布时间】:2019-08-31 05:12:00
【问题描述】:

我发现利用无服务器到 AWS Lambda 正确打包和部署 dotnet 函数(使用 dotnet core 2.1 运行时)是一项挑战。除了使用 SAM 和 dotnet deploy lambda-serverless 命令的示例之外,我没有找到任何示例。

示例:How do you package up a visual studio aws serverless project?

使用命令行和无服务器,需要做什么才能将 dotnet 核心功能正确部署到 AWS Lambda?这甚至可以使用无服务器框架实现吗?

【问题讨论】:

    标签: amazon-web-services .net-core aws-lambda serverless-framework serverless


    【解决方案1】:

    我终于能够克服我的问题。

    1. cd 到 .csproj 文件夹
    2. dotnet restore
    3. dotnet lambda package 使用 dotnet lambda 工具 dotnet tool install -g Amazon.Lambda.Tools
    4. 假设您的 serverless.ymal 的其余部分设置正确,请确保您的 serverless.yml 具有包属性,其中包含指向 dotnet lambda 包生成的 .zip 文件的工件,例如:
    package:
      artifact: ./<projectFolderName>/src/<projectName>/bin/Release/netcoreapp2.1/<zipFileName>.zip
    
    1. 您需要一个使用 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)
        {
    
        }
    }
    

    注意:其中一些可以从模板生成。

    1. 做一个常规的sls deploy

    除了互联网上现成的内容之外,这些步骤突出了我必须克服的一些障碍才能使我的工作正常。

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2018-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      相关资源
      最近更新 更多