From 44e29177f21aaae933b1f47b692fd3069d7907c7 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Tue, 25 Mar 2025 15:07:01 -0400 Subject: [PATCH 1/3] Update message processing template --- .../961abe16-3efd-46df-b706-2b0b3bcca35d.json | 11 +++ .../BlueprintBaseName.1.csproj | 3 +- .../src/BlueprintBaseName.1/Readme.md | 92 ++++++++++++++++++- .../src/BlueprintBaseName.1/Startup.cs | 11 ++- .../BlueprintBaseName.1/serverless.template | 2 +- 5 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 .autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json diff --git a/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json b/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json new file mode 100644 index 000000000..b401bf5ac --- /dev/null +++ b/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.Templates", + "Type": "Patch", + "ChangelogMessages": [ + "Update message processing framework template." + ] + } + ] +} \ No newline at end of file diff --git a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj index 17a2430cb..798668b44 100644 --- a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj +++ b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj @@ -11,10 +11,11 @@ true - + + \ No newline at end of file diff --git a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md index db64a3b66..ac2b6d16c 100644 --- a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md +++ b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md @@ -20,13 +20,95 @@ The framework reduces the amount of boiler-plate code developers need to write, The framework supports Open Telemetry via the [AWS.Messaging.Telemetry.OpenTelemetry](https://www.nuget.org/packages/AWS.Messaging.Telemetry.OpenTelemetry/) package. Refer to its [README](https://github.com/awslabs/aws-dotnet-messaging/blob/main/src/AWS.Messaging.Telemetry.OpenTelemetry/README.md) to enable instrumentation. -## Testing Locally +## Local Testing Guide -The functions can be tested with the [Mock Lambda Test Tool](https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool) in Visual Studio or other IDEs. +### Prerequisites +The functions can be tested with the [Mock Lambda Test Tool](https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool-v2). + +1. Install the AWS Lambda Test Tool: +```bash +dotnet tool install -g amazon.lambda.testtool +``` + +2. Get the test tool version: + +``` +dotnet lambda-test-tool info +``` + +### Setup Steps + + +1. Build the project + +``` +dotnet build +``` + +2. Start the Lambda Test Tool: + +``` +dotnet lambda-test-tool start --lambda-emulator-port 5050 +``` + +3. Configure the project: +* Update Properties/launchSettings.json with the test tool version and function handler name. + +###$ Example launchSettings.json + +```json +{ + "profiles": { + "Default": { + "workingDirectory": ".\\bin\\$(Configuration)\\net8.0", + "commandName": "Executable", + "commandLineArgs": "exec --depsfile ./BlueprintBaseName.1.deps.json --runtimeconfig ./BlueprintBaseName.1.runtimeconfig.json %USERPROFILE%/.dotnet/tools/.store/amazon.lambda.testtool/${VERSION}/amazon.lambda.testtool/${VERSION}/content/Amazon.Lambda.RuntimeSupport/net8.0/Amazon.Lambda.RuntimeSupport.dll BlueprintBaseName.1::BlueprintBaseName._1.Functions_Handler_Generated::Handler", + "executablePath": "dotnet", + "environmentVariables": { + "AWS_LAMBDA_RUNTIME_API": "localhost:5050/MyFunction", + "QUEUE_URL": "QUEUE_URL" + } + } + } +} + +``` + + +### Running the project + +### Option 1: Using Visual Studio +1. Update launchSettings.json with the correct test tool version +2. Run the project from Visual Studio + + +### Option 2: Using Command Line + + +``` +cd bin\Debug\net8.0 +$env:AWS_LAMBDA_RUNTIME_API = "localhost:5050/MyFunction" +$env:VERSION = "0.9.1" // Use the version returned from dotnet lambda-test-tool info + +dotnet exec --depsfile ./BlueprintBaseName.1.deps.json --runtimeconfig ./BlueprintBaseName.1.runtimeconfig.json "$env:USERPROFILE\.dotnet\tools\.store\amazon.lambda.testtool\$env:VERSION\amazon.lambda.testtool\$env:VERSION\content\Amazon.Lambda.RuntimeSupport\net8.0\Amazon.Lambda.RuntimeSupport.dll" BlueprintBaseName.1::BlueprintBaseName._1.Functions_Handler_Generated::Handler + + +``` + +### Testing + +The project includes sample payloads in  + +```plaintext +.lambda-test-tool\SavedRequests +``` + +: + +1. "Sender Sample Request" - can be used to invoke the Sender function. Note that this will send an SQS message to the queue configured in `launchSettings.json` + +2. "Handler Sample Request" - can be used to invoke the Handler function. This mocks the SQS message, and does not require an actual queue. -The project includes two sample payloads, one for each function handler. -1. "Sender Sample Request" can be used to invoke the Sender function. Note that this will send an SQS message to the queue configured in `launchSettings.json` -2. "Handler Sample Request" can be used to invoke the Handler function. This mocks the SQS message, and does not require an actual queue. ## Deploying and Testing from Visual Studio diff --git a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Startup.cs b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Startup.cs index 70df5c1b7..05b81bd9f 100644 --- a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Startup.cs +++ b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Startup.cs @@ -1,5 +1,6 @@ using Amazon.Lambda.Annotations; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace BlueprintBaseName._1; @@ -14,10 +15,14 @@ public class Startup /// the lifetime of the Lambda compute container. Services injected as parameters are created within the scope /// of the function invocation. /// - public void ConfigureServices(IServiceCollection services) + public HostApplicationBuilder ConfigureHostBuilder() { + + var builder = new HostApplicationBuilder(); + + // Here we'll configure the AWS Message Processing Framework for .NET. - services.AddAWSMessageBus(builder => + builder.Services.AddAWSMessageBus(builder => { // Register that you'll publish messages of type "GreetingMessage" to the specified queue URL. // 1. When deployed, the QUEUE_URL variable will be set to the queue that is defined in serverless.template @@ -33,6 +38,8 @@ public void ConfigureServices(IServiceCollection services) // You can register additional message type and handler mappings here as well. }); + + return builder; } } diff --git a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/serverless.template b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/serverless.template index 81d94c75d..da5cc139f 100644 --- a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/serverless.template +++ b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/serverless.template @@ -1,7 +1,7 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Transform": "AWS::Serverless-2016-10-31", - "Description": "AWS Message Processing Framework for .NET Template. This template is partially managed by Amazon.Lambda.Annotations (v1.6.1.0).", + "Description": "AWS Message Processing Framework for .NET Template. This template is partially managed by Amazon.Lambda.Annotations (v1.7.0.0).", "Resources": { "MessageProcessingFrameworkDemoQueue": { "Type": "AWS::SQS::Queue" From a90e9249d62210a5f005b3e9f28d6a94c4394e49 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Wed, 26 Mar 2025 11:08:51 -0400 Subject: [PATCH 2/3] PR comments --- .../changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json | 2 +- .../template/src/BlueprintBaseName.1/Readme.md | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json b/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json index b401bf5ac..37d88a440 100644 --- a/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json +++ b/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json @@ -4,7 +4,7 @@ "Name": "Amazon.Lambda.Templates", "Type": "Patch", "ChangelogMessages": [ - "Update message processing framework template." + "Update the AWS Message Processing Framework for .NET project template." ] } ] diff --git a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md index ac2b6d16c..d3f6ed952 100644 --- a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md +++ b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md @@ -23,14 +23,14 @@ The framework supports Open Telemetry via the [AWS.Messaging.Telemetry.OpenTelem ## Local Testing Guide ### Prerequisites -The functions can be tested with the [Mock Lambda Test Tool](https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool-v2). +The functions can be tested with the [Lambda Test Tool](https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool-v2). -1. Install the AWS Lambda Test Tool: +1. Install the Lambda Test Tool: ```bash dotnet tool install -g amazon.lambda.testtool ``` -2. Get the test tool version: +2. Get the Lambda Test Tool version: ``` dotnet lambda-test-tool info @@ -52,7 +52,7 @@ dotnet lambda-test-tool start --lambda-emulator-port 5050 ``` 3. Configure the project: -* Update Properties/launchSettings.json with the test tool version and function handler name. +* Update Properties/launchSettings.json with the Lambda Test Tool version and function handler name. ###$ Example launchSettings.json @@ -78,7 +78,7 @@ dotnet lambda-test-tool start --lambda-emulator-port 5050 ### Running the project ### Option 1: Using Visual Studio -1. Update launchSettings.json with the correct test tool version +1. Update launchSettings.json with the correct Lambda Test Tool version 2. Run the project from Visual Studio From 08e240c1bf27493459a615463ee65d6253f742a4 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Thu, 27 Mar 2025 13:29:48 -0400 Subject: [PATCH 3/3] update messaging version --- .../template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj index 798668b44..83fa3a43c 100644 --- a/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj +++ b/Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj @@ -15,7 +15,7 @@ - + \ No newline at end of file