I'm new to Mono and .NET ecosystem in general and the official guide doesn't seem to apply.
-
The official guide applies to .net Core, is there a (good) reason not to use that? – Stefan Nov 23 '18 at 10:54
-
Also; see: https://stackoverflow.com/questions/37738106/net-core-vs-mono – Stefan Nov 23 '18 at 10:56
2 Answers
Actually the guide does apply, but I had to install dotnet-cli
first (see how) which does not come with Mono distribution on OS X.
Also I need a function zip file itself rather than the ability to create a function, which is not the usual or recommended workflow of course.
Building such a zip from docker container:
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/
File structure:
src/LambdaTest
├── Function.cs
└── LambdaTest.csproj
Function.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>

- 335
- 5
- 16
Since you are new to the "Mono and .NET eco system", I strongly advise you to use .NET Core
.
The .NET Core
ecosystem is able to deploy a self contained environment, which is needed for most cloud services, such as AWS Lambda (as you can read in the guide you provided).
You can start .NET Core
projects out of the box when using Visual Studio 2017, and there are template packages available on nuget .
More info can be found here, in the AWS docs:

- 17,448
- 11
- 60
- 79
-
1I see. I think I could've used .NET Core as well, it occurs to me now that .NET Core vs Mono difference is not the reason why I had difficulties with the guide. – Pavel Nov 23 '18 at 11:38