rab*_*ens 3 c# amazon-web-services aws-lambda
我安装了 AWS Tools for Visual Studio 并创建了一个基本的 Lambda 函数。我在代码中没有进行任何更改,但是当dotnet publish通过 Visual Studio 运行或进行发布时,我得到:
C:\Users\Jens Rabe\source\repos\lambdatest\SimpleLambdaTest>dotnet 发布
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 42.2 ms for C:\Users\Jens Rabe\source\repos\lambdatest\SimpleLambdaTest\SimpleLambdaTest.csproj.
Function.cs(2,12): error CS0246: The type or namespace name 'LambdaSerializerAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Jens Rabe\source\repos\lambdatest\SimpleLambdaTest\SimpleLambdaTest.csproj]
Function.cs(2,12): error CS0246: The type or namespace name 'LambdaSerializer' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Jens Rabe\source\repos\lambdatest\SimpleLambdaTest\SimpleLambdaTest.csproj]
Function.cs(13,53): error CS0246: The type or namespace name 'ILambdaContext' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\Jens Rabe\source\repos\lambdatest\SimpleLambdaTest\SimpleLambdaTest.csproj]
Run Code Online (Sandbox Code Playgroud)
这是我的SimpleLambdaTest.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>
Run Code Online (Sandbox Code Playgroud)
我没有改变Function.cs:
// 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 AlexaWhereIs {
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当尝试从 VS 中编译它时,它还抱怨这三件事不可用。
我缺少什么?
我Amazon.Lambda.Templates使用命令行安装了:
dotnet new -i Amazon.Lambda.Templates
Run Code Online (Sandbox Code Playgroud)
并重新创建了该函数
dotnet new lambda.EmptyFunction --name SimpleLambdaTest --profile default --region eu-west-1
Run Code Online (Sandbox Code Playgroud)
然后,我将该项目导入到我的解决方案中,并且它可以正常构建和发布。但是,上传后,Visual Studio 崩溃并显示“Visual Studio 社区已停止工作”。
所以我部署了一次,Visual Studio 崩溃了,如上所述。但随后我可以在命令行上重新部署它并dotnet lambda deploy-function使用 进行测试dotnet lambda invoke-function。不太方便,但可以作为解决方法。
有任何想法吗?
小智 5
function.cs 似乎缺少对 Amazon.Lambda.Core 的库引用。请在 function.cs 文件的开头使用以下导入行
using Amazon.Lambda.Core;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3523 次 |
| 最近记录: |