I installed AWS Tools for Visual Studio and created a basic Lambda Function. I changed nothing in the code, but when running dotnet publish or doing the publish through Visual Studio, I get:
C:\Users\Jens Rabe\source\repos\lambdatest\SimpleLambdaTest>dotnet publish
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]
This is my 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>
I didn't change the Function.cs either:
// 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();
}
}
}
When trying to compile it from within VS, it also complains about the three things not available.
What am I missing?
Followup 1
I installed the Amazon.Lambda.Templates using the command line:
dotnet new -i Amazon.Lambda.Templates
And recreated the function with
dotnet new lambda.EmptyFunction --name SimpleLambdaTest --profile default --region eu-west-1
I then imported the project in my solution, and it builds and publishes fine. However, after uploading, Visual Studio crashes with the "Visual Studio Community has stopped working".
Followup 2
So I deployed it once and Visual Studio crashed as stated above. But then I can redeploy it on the command line with dotnet lambda deploy-function and test it with dotnet lambda invoke-function. Not that convenient but will do as a workaround.
Any ideas?