LambdaSharp 0.8.4.1
dotnet add package LambdaSharp --version 0.8.4.1
NuGet\Install-Package LambdaSharp -Version 0.8.4.1
<PackageReference Include="LambdaSharp" Version="0.8.4.1" />
paket add LambdaSharp --version 0.8.4.1
#r "nuget: LambdaSharp, 0.8.4.1"
// 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:
DefaultIgnoreCondition
:JsonIgnoreCondition.WhenWritingNull
IncludeFields
:true
NumberHandling
:JsonNumberHandling.AllowReadingFromString
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 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. |
-
net6.0
- Amazon.Lambda.Serialization.SystemTextJson (>= 2.3.1)
- AWSSDK.CloudWatchEvents (>= 3.7.100.106)
- AWSSDK.Core (>= 3.7.106.13)
- AWSSDK.KeyManagementService (>= 3.7.101.81)
- AWSSDK.SQS (>= 3.7.100.106)
- AWSSDK.XRay (>= 3.7.102.87)
- AWSXRayRecorder.Core (>= 2.14.0)
- AWSXRayRecorder.Handlers.AwsSdk (>= 2.12.0)
- AWSXRayRecorder.Handlers.System.Net (>= 2.11.0)
- LambdaSharp.Logging (>= 0.8.4.1)
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.CustomResource
Serverless .NET for AWS - CloudFormation Custom Resource Library |
|
LambdaSharp.SimpleQueueService
Serverless .NET for AWS - SQS Lambda 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 | 43,600 | 4/18/2023 |
0.8.4 | 22,401 | 3/10/2022 |
0.8.3.5 | 2,893 | 3/4/2022 |
0.8.3.4 | 2,141 | 7/15/2021 |
0.8.3.3 | 1,634 | 7/15/2021 |
0.8.3.2 | 1,669 | 6/17/2021 |
0.8.3 | 1,613 | 5/19/2021 |
0.8.2.4 | 1,733 | 4/30/2021 |
0.8.2.3 | 2,057 | 4/2/2021 |
0.8.2.2 | 1,635 | 3/18/2021 |
0.8.2 | 7,439 | 2/16/2021 |
0.8.1.3 | 12,376 | 10/21/2020 |
0.8.1.2 | 637 | 10/21/2020 |
0.8.1 | 701 | 8/28/2020 |
0.8.1-rc1 | 412 | 8/24/2020 |
0.8.0.6 | 922 | 7/15/2020 |
0.8.0.5 | 668 | 7/2/2020 |
0.8.0.3 | 681 | 6/19/2020 |
0.8.0.2 | 671 | 6/3/2020 |
0.8.0 | 715 | 5/18/2020 |
0.7.0.8 | 951 | 2/25/2020 |
0.7.0.4 | 2,676 | 10/18/2019 |
0.7.0.3 | 4,029 | 10/3/2019 |
0.7.0 | 723 | 9/11/2019 |
0.6.1 | 1,420 | 9/5/2019 |
0.6.0.3 | 888 | 7/1/2019 |
0.6.0.2 | 883 | 6/27/2019 |
0.6.0.1 | 3,625 | 6/12/2019 |
0.6.0 | 3,709 | 5/10/2019 |
0.5.0 | 3,095 | 2/12/2019 |