LambdaSharp 0.8.4

.NET 6.0
NuGet\Install-Package LambdaSharp -Version 0.8.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package LambdaSharp --version 0.8.4
<PackageReference Include="LambdaSharp" Version="0.8.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LambdaSharp --version 0.8.4
#r "nuget: LambdaSharp, 0.8.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install LambdaSharp as a Cake Addin
#addin nuget:?package=LambdaSharp&version=0.8.4

// Install LambdaSharp as a Cake Tool
#tool nuget:?package=LambdaSharp&version=0.8.4

LambdaSharp

This package contains interfaces and classes used for building Lambda functions on AWS.

Visit LambdaSharp.NET to learn more about building serverless .NET solutions on AWS.

ALambdaFunction

The ALambdaFunction base class provides functionality to initialize and process requests/responses using streams.

public class Function : ALambdaFunction {

    //--- Methods ---
    public override async Task InitializeAsync(LambdaConfig config) {

        // TO-DO: add function initialization and reading configuration settings
    }

    public override sealed async Task<Stream> ProcessMessageStreamAsync(Stream stream) {
        var responseStream = new MemoryStream();
        responseStream.Write(Encoding.UTF8.GetBytes("Hello World!"));
        responseStream.Position = 0;
        return responseStream;
    }
}

ALambdaFunction<TRequest, TResponse>

The ALambdaFunction<TRequest, TResponse> base class adds functionality to deserialize/serialize the requests/responses with the JSON serializer specified in the constructor.

public sealed class Function : ALambdaFunction<FunctionRequest, FunctionResponse> {

    //--- Constructors ---
    public Function() : base(new LambdaSharp.Serialization.LambdaSystemTextJsonSerializer()) { }

    //--- Methods ---
    public override async Task InitializeAsync(LambdaConfig config) {

        // TO-DO: add function initialization and reading configuration settings
    }

    public override async Task<FunctionResponse> ProcessMessageAsync(FunctionRequest request) {

        // TO-DO: add business logic

        return new FunctionResponse();
    }
}

JSON Serializers

This packages contains two serializers: LambdaSystemTextJsonSerializer and LambdaSourceGeneratorJsonSerializer.

LambdaSystemTextJsonSerializer is the recommended JSON serializer. LambdaSourceGeneratorJsonSerializer should be considered experimental as JSON source generators have many limitations.

LambdaSystemTextJsonSerializer

The construtor takes an optional callback to customize the JSON serialization options.

new LambdaSharp.Serialization.LambdaSystemTextJsonSerializer(options => {
    options.Converters.Add(new MyJsonConverter());
});

This following options are used by default:

  1. DefaultIgnoreCondition: JsonIgnoreCondition.WhenWritingNull
  2. IncludeFields: true
  3. NumberHandling: JsonNumberHandling.AllowReadingFromString
  4. Encoder: System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping

LambdaSourceGeneratorJsonSerializer

This class uses JSON serialization source generators, which avoids using reflection during runtime by creating the serialization/deserialization logic during compile time instead. Review current limitations of this approach and provide sufficient test coverage to ensure expected behavior.

First declare a partial class to hold the serialization/deserialization logic for the specified types.

[JsonSerializable(typeof(FunctionRequest))]
[JsonSerializable(typeof(FunctionResponse))]
public partial class FunctionJsonSerializerContext : JsonSerializerContext { }

Then pass in the default instance to the constructor.

new LambdaSharp.Serialization.LambdaSourceGeneratorJsonSerializer(FunctionJsonSerializerContext.Default)

LambdaSharp.Serialization.NewtonsoftJson (Additional Package)

The LambdaSharp.Serialization.NewtonsoftJson package is provided as a separate package. It is only recommended for legacy projects that require compatibility with JSON.NET annotations.

The construtor takes an optional callback to customize the JSON.NET serialization settings.

new LambdaSharp.Serialization.NewtonsoftJson(settings => {
    settings.NullValueHandling = NullValueHandling.Include;
})

Logging

The ALambdaFunction base classes includes logging methods to make it easy to report information to CloudWatch Logs and optionally to an error aggregator, such as Rollbar.

  • LogDebug(): Log a debugging message. This message will only appear in the log when debug logging is enabled and will not be forwarded to an error aggregator.
  • LogInfo(): Log an informational message. This message will only appear in the log and not be forwarded to an error aggregator.
  • LogWarn(): Log a warning message. This message will be reported if an error aggregator is configured for the <c>LambdaSharp.Core</c> module.
  • LogError(): Log an exception as an error. This message will be reported if an error aggregator is configured for the <c>LambdaSharp.Core</c> module.
  • LogErrorAsInfo(): Log an exception as an information message. This message will only appear in the log and not be forwarded to an error aggregator.
  • LogErrorAsWarning(): Log an exception as a warning. This message will be reported if an error aggregator is configured for the <c>LambdaSharp.Core</c> module.
  • LogFatal(): Log an exception with a custom message as a fatal error. This message will be reported if an error aggregator is configured for the <c>LambdaSharp.Core</c> module.
  • LogMetric(): Log a CloudWatch metric. The metric is picked up by CloudWatch logs and automatically ingested as a CloudWatch metric.

License

Copyright (c) 2018-2022 LambdaSharp (λ#)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on LambdaSharp:

Package Downloads
LambdaSharp.Slack

Serverless .NET for AWS - Slack Lambda Library

LambdaSharp.ApiGateway

Serverless .NET for AWS - API Gateway Lambda Library

LambdaSharp.Schedule

Serverless .NET for AWS - CloudWatch Schedule Lambda Library

LambdaSharp.Serialization.NewtonsoftJson

Serverless .NET for AWS - Serialization Library using Newtonsoft.Json

LambdaSharp.CustomResource

Serverless .NET for AWS - CloudFormation Custom Resource Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.4 906 3/10/2022
0.8.3.5 433 3/4/2022
0.8.3.4 1,038 7/15/2021
0.8.3.3 583 7/15/2021
0.8.3.2 637 6/17/2021
0.8.3 514 5/19/2021
0.8.2.4 622 4/30/2021
0.8.2.3 989 4/2/2021
0.8.2.2 565 3/18/2021
0.8.2 1,724 2/16/2021
0.8.1.3 10,197 10/21/2020
0.8.1.2 396 10/21/2020
0.8.1 458 8/28/2020
0.8.1-rc1 264 8/24/2020
0.8.0.6 662 7/15/2020
0.8.0.5 416 7/2/2020
0.8.0.3 427 6/19/2020
0.8.0.2 434 6/3/2020
0.8.0 458 5/18/2020
0.7.0.8 699 2/25/2020
0.7.0.4 2,438 10/18/2019
0.7.0.3 3,771 10/3/2019
0.7.0 477 9/11/2019
0.6.1 1,155 9/5/2019
0.6.0.3 612 7/1/2019
0.6.0.2 601 6/27/2019
0.6.0.1 3,350 6/12/2019
0.6.0 3,451 5/10/2019
0.5.0 2,837 2/12/2019