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..37d88a440 --- /dev/null +++ b/.autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.Templates", + "Type": "Patch", + "ChangelogMessages": [ + "Update the AWS Message Processing Framework for .NET project 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..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 @@ -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..d3f6ed952 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 [Lambda Test Tool](https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool-v2). + +1. Install the Lambda Test Tool: +```bash +dotnet tool install -g amazon.lambda.testtool +``` + +2. Get the Lambda 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 Lambda 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 Lambda 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"