LambdaSharp 0.8.4.1

dotnet add package LambdaSharp --version 0.8.4.1
NuGet\Install-Package LambdaSharp -Version 0.8.4.1
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.
<PackageReference Include="LambdaSharp" Version="0.8.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LambdaSharp --version 0.8.4.1
#r "nuget: LambdaSharp, 0.8.4.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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.1

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

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 Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (8)

Showing the top 5 NuGet packages that depend on LambdaSharp:

Package Downloads
LambdaSharp.Serialization.NewtonsoftJson

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

LambdaSharp.Schedule

Serverless .NET for AWS - CloudWatch Schedule Lambda Library

LambdaSharp.ApiGateway

Serverless .NET for AWS - API Gateway Lambda Library

LambdaSharp.Slack

Serverless .NET for AWS - Slack Lambda Library

LambdaSharp.CustomResource

Serverless .NET for AWS - CloudFormation Custom Resource Library

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on LambdaSharp:

Repository Stars
LambdaSharp/LambdaSharpTool
Serverless .NET on AWS - λ# is a CLI and Framework for Rapid Application Development using .NET on AWS
Version Downloads Last updated
0.8.4.1 18,744 4/18/2023
0.8.4 13,857 3/10/2022
0.8.3.5 2,722 3/4/2022
0.8.3.4 2,032 7/15/2021
0.8.3.3 1,520 7/15/2021
0.8.3.2 1,523 6/17/2021
0.8.3 1,482 5/19/2021
0.8.2.4 1,594 4/30/2021
0.8.2.3 1,935 4/2/2021
0.8.2.2 1,509 3/18/2021
0.8.2 7,328 2/16/2021
0.8.1.3 12,345 10/21/2020
0.8.1.2 613 10/21/2020
0.8.1 662 8/28/2020
0.8.1-rc1 376 8/24/2020
0.8.0.6 871 7/15/2020
0.8.0.5 630 7/2/2020
0.8.0.3 657 6/19/2020
0.8.0.2 649 6/3/2020
0.8.0 679 5/18/2020
0.7.0.8 925 2/25/2020
0.7.0.4 2,644 10/18/2019
0.7.0.3 3,994 10/3/2019
0.7.0 690 9/11/2019
0.6.1 1,387 9/5/2019
0.6.0.3 847 7/1/2019
0.6.0.2 851 6/27/2019
0.6.0.1 3,592 6/12/2019
0.6.0 3,672 5/10/2019
0.5.0 3,060 2/12/2019