我是 Mono 和 .NET 生态系统的新手,并且 the official guide似乎不适用。
最佳答案
实际上该指南确实适用,但我必须先安装 dotnet-cli
( see how ),它在 OS X 上没有随 Mono 发行版一起提供。
此外,我还需要函数 zip 文件本身,而不是创建函数的能力,这当然不是通常或推荐的工作流程。
从 docker 容器构建这样的 zip:
FROM mono
RUN curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin
COPY src /src
WORKDIR /src
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
RUN /root/.dotnet/dotnet publish LambdaTest/LambdaTest.csproj
RUN zip -r -j dotnet.zip LambdaTest/bin/Debug/netcoreapp2.1/publish/
文件结构:
src/LambdaTest
├── Function.cs
└── LambdaTest.csproj
函数.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace dotnet
{
public class Function
{
/// <summary>
/// A simple function that takes a string and does a ToUpper
/// </summary>
/// <param name="input"></param>
/// <param name="context"></param>
/// <returns></returns>
public string FunctionHandler(string input, ILambdaContext context)
{
return input?.ToUpper();
}
}
}
LambdaTest.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Core" Version="1.0.0" />
<PackageReference Include="Amazon.Lambda.Serialization.Json" Version="1.4.0" />
</ItemGroup>
</Project>
关于.net - 如何使用 Mono 为 AWS Lambda 函数创建 .NET 函数代码 zip 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53445281/