Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Lambda v2 docs and snippets #6482

Merged
merged 22 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions Snippets/SQSLambda/SQSLambda.sln
@@ -1,21 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
# Visual Studio Version 17
VisualStudioVersion = 17.8.34601.278
MinimumVisualStudioVersion = 15.0.26730.12
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQSLambda", "SQSLambda_0\SQSLambda_0.csproj", "{EE9BFF4F-158A-4DFE-ABAC-60959DD8DCC5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SQSLambda_1", "SQSLambda_1\SQSLambda_1.csproj", "{CB0C031E-9860-4ABA-BE91-AE962FDE22D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQSLambda_1", "SQSLambda_1\SQSLambda_1.csproj", "{CB0C031E-9860-4ABA-BE91-AE962FDE22D7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SQSLambda_2", "SQSLambda_2\SQSLambda_2.csproj", "{46B65C7D-35FF-44F8-A6FD-F75296235461}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE9BFF4F-158A-4DFE-ABAC-60959DD8DCC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE9BFF4F-158A-4DFE-ABAC-60959DD8DCC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB0C031E-9860-4ABA-BE91-AE962FDE22D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB0C031E-9860-4ABA-BE91-AE962FDE22D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB0C031E-9860-4ABA-BE91-AE962FDE22D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB0C031E-9860-4ABA-BE91-AE962FDE22D7}.Release|Any CPU.Build.0 = Release|Any CPU
{46B65C7D-35FF-44F8-A6FD-F75296235461}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46B65C7D-35FF-44F8-A6FD-F75296235461}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46B65C7D-35FF-44F8-A6FD-F75296235461}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46B65C7D-35FF-44F8-A6FD-F75296235461}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 0 additions & 12 deletions Snippets/SQSLambda/SQSLambda_0/SQSLambda_0.csproj

This file was deleted.

@@ -1,7 +1,5 @@
using System.Threading.Tasks;

using Amazon.Lambda.SQSEvents;

using NServiceBus;

#region native-lambda-sqs-message
Expand All @@ -20,5 +18,4 @@ public Task Handle(TestMessage message, IMessageHandlerContext context)

public class TestMessage
{
}

}
5 changes: 2 additions & 3 deletions Snippets/SQSLambda/SQSLambda_1/SQSLambda_1.csproj
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AWSProjectType>Lambda</AWSProjectType>
<RootNamespace />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.AwsLambda.SQS" Version="1.*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="3.*" />
</ItemGroup>

</Project>
14 changes: 1 addition & 13 deletions Snippets/SQSLambda/SQSLambda_1/Usage.cs
@@ -1,10 +1,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using Amazon.Lambda.Core;
using Amazon.Lambda.SQSEvents;

using NServiceBus;

class Usage
Expand Down Expand Up @@ -63,17 +61,6 @@ static void Recoverability(AwsLambdaSQSEndpointConfiguration endpointConfigurati
#endregion
}

static void ConfigureErrorQueue(AwsLambdaSQSEndpointConfiguration endpointConfiguration)
{
#region aws-configure-error-queue

var advanced = endpointConfiguration.AdvancedConfiguration;

advanced.SendFailedMessagesTo("<error-queue>");

#endregion
}

static void ConfigureDontMoveToErrors(AwsLambdaSQSEndpointConfiguration endpointConfiguration)
{
#region aws-configure-dont-move-to-error
Expand All @@ -82,6 +69,7 @@ static void ConfigureDontMoveToErrors(AwsLambdaSQSEndpointConfiguration endpoint

#endregion
}

static void ConfigureSerializer(AwsLambdaSQSEndpointConfiguration endpointConfiguration)
{
#region aws-custom-serializer
Expand Down
@@ -1,7 +1,5 @@
using System.Threading.Tasks;

using Amazon.Lambda.SQSEvents;

using NServiceBus;

#region native-lambda-sqs-message
Expand All @@ -20,5 +18,4 @@ public Task Handle(TestMessage message, IMessageHandlerContext context)

public class TestMessage
{
}

}
10 changes: 10 additions & 0 deletions Snippets/SQSLambda/SQSLambda_2/SQSLambda_2.csproj
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.AwsLambda.SQS" Version="2.0.0-alpha.1" />
</ItemGroup>

</Project>
Expand Up @@ -25,10 +25,9 @@ class Usage
public async Task FunctionHandler(SQSEvent evnt, ILambdaContext context)
{
var cancellationDelay = context.RemainingTime.Subtract(TimeSpan.FromSeconds(10));
using (var cancellationTokenSource = new CancellationTokenSource(cancellationDelay))
{
await endpoint.Process(evnt, context, cancellationTokenSource.Token);
}
using var cancellationTokenSource = new CancellationTokenSource(cancellationDelay);

await endpoint.Process(evnt, context, cancellationTokenSource.Token);
}

#endregion
Expand All @@ -39,7 +38,7 @@ static void CustomDiagnostics(AwsLambdaSQSEndpointConfiguration endpointConfigur

var advanced = endpointConfiguration.AdvancedConfiguration;

advanced.CustomDiagnosticsWriter(diagnostics =>
advanced.CustomDiagnosticsWriter((diagnostics, token) =>
{
context.Logger.LogLine(diagnostics);
return Task.CompletedTask;
Expand All @@ -60,23 +59,6 @@ static void Recoverability(AwsLambdaSQSEndpointConfiguration endpointConfigurati
});

#endregion

#region aws-unrestricted-delayed-delivery

endpointConfiguration.Transport.UnrestrictedDurationDelayedDelivery();

#endregion
}

static void ConfigureErrorQueue(AwsLambdaSQSEndpointConfiguration endpointConfiguration)
{
#region aws-configure-error-queue

var advanced = endpointConfiguration.AdvancedConfiguration;

advanced.SendFailedMessagesTo("<error-queue>");

#endregion
}

static void ConfigureDontMoveToErrors(AwsLambdaSQSEndpointConfiguration endpointConfiguration)
Expand All @@ -87,11 +69,12 @@ static void ConfigureDontMoveToErrors(AwsLambdaSQSEndpointConfiguration endpoint

#endregion
}

static void ConfigureSerializer(AwsLambdaSQSEndpointConfiguration endpointConfiguration)
{
#region aws-custom-serializer

endpointConfiguration.UseSerialization<NewtonsoftSerializer>();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#endregion
}
Expand All @@ -100,8 +83,7 @@ static void RoutingConfiguration(AwsLambdaSQSEndpointConfiguration endpointConfi
{
#region aws-configure-routing

var transport = endpointConfiguration.Transport;
var routing = transport.Routing();
var routing = endpointConfiguration.RoutingSettings;
routing.RouteToEndpoint(typeof(ACommand), "<destination>");

#endregion
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions menu/menu.yaml
Expand Up @@ -166,6 +166,8 @@
Title: 2016-07-05
- Url: nservicebus/upgrades/callbacks-1to2
Title: Callbacks 1 to 2
- Url: nservicebus/upgrades/sqs-lambda-1to2
Title: AwsLambda SQS 1 to 2
- Url: nservicebus/upgrades/bridge-2to3
Title: Messaging Bridge 2 to 3
- Url: nservicebus/upgrades/8to9
Expand Down
26 changes: 10 additions & 16 deletions nservicebus/hosting/aws-lambda-simple-queue-service/index.md
Expand Up @@ -4,7 +4,7 @@ component: SQSLambda
summary: Hosting NServiceBus endpoints with AWS Lambda triggered by Simple Queue Service
related:
- samples/aws/lambda-sqs
reviewed: 2023-04-28
reviewed: 2024-03-06
redirects:
- previews/aws-lambda-simple-queue-service
---
Expand Down Expand Up @@ -35,7 +35,13 @@ Transport installers are not supported. The creation of the required queues may

## Configuration

The configuration API exposes NServiceBus configuration options to allow customization; however, not all options will be [applicable to execution within AWS Lambda](./analyzers.md).
The configuration API exposes NServiceBus configuration options to allow customization; however, not all options will [apply to execution within AWS Lambda](./analyzers.md).

### Serializer

Configure [serializer](/nservicebus/serialization/) to use:

snippet: aws-custom-serializer

### Routing

Expand All @@ -49,26 +55,14 @@ snippet: aws-configure-routing

snippet: aws-custom-diagnostics

### Delayed Retries

partial: delayed-delivery

### Error queue

Messages which fail all retries are moved to the error queue, which must be defined as follows:
### Error handling

snippet: aws-configure-error-queue

Alternatively, the endpoint may be configured to never move failing messages to the error queue as follows:
Messages that fail all retries are [moved to the default `error` queue](/nservicebus/recoverability/#fault-handling). Alternatively, the endpoint may be configured to instead use [the automatic AWS Lambda error handling](https://docs.aws.amazon.com/lambda/latest/dg/invocation-retries.html) by rethrowing the exception:

snippet: aws-configure-dont-move-to-error

### Serializer

The default serializer is the [XmlSerializer](/nservicebus/serialization/xml.md). A different serializer can be configured:

snippet: aws-custom-serializer

### Licenses

The license is provided via the `NSERVICEBUS_LICENSE` environment variable, which can be set via the Function settings in the [Lambda console](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html).
Expand Down

This file was deleted.

@@ -1,3 +1,5 @@
### Delayed Retries

[Delayed retries](/nservicebus/recoverability/configure-delayed-retries.md) are disabled by default when using AWS Lambda. Delayed retries cam be enabled as follows:

snippet: aws-delayed-retries
14 changes: 14 additions & 0 deletions nservicebus/upgrades/sqs-lambda-1to2.md
@@ -0,0 +1,14 @@
---
title: Upgrade Version 1 to 2
summary: Instructions on how to upgrade NServiceBus.AwsLambda.SQS Version 1 to 2.
component: SQSLambda
reviewed: 2024-03-06
isUpgradeGuide: true
upgradeGuideCoreVersions:
- 8
- 9
---

## Delayed retries enabled by default
andreasohlund marked this conversation as resolved.
Show resolved Hide resolved

In Version 2 delayed retries are enabled by default. See the [delayed retries documentation for more details](/nservicebus/recoverability/configure-delayed-retries.md#disabling-through-code).
10 changes: 0 additions & 10 deletions samples/aws/lambda-sqs/SQSLambda_0/Messages/Messages.csproj

This file was deleted.

51 changes: 0 additions & 51 deletions samples/aws/lambda-sqs/SQSLambda_0/RegularEndpoint/Program.cs

This file was deleted.

This file was deleted.