Skip to content

Update Messaging Processing Framework template project #2020

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

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .autover/changes/961abe16-3efd-46df-b706-2b0b3bcca35d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Projects": [
{
"Name": "Amazon.Lambda.Templates",
"Type": "Patch",
"ChangelogMessages": [
"Update the AWS Message Processing Framework for .NET project template."
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.6.1" />
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.7.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
<PackageReference Include="AWS.Messaging.Lambda" Version="0.9.0" />
<PackageReference Include="AWS.Messaging.Lambda" Version="0.10.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Amazon.Lambda.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace BlueprintBaseName._1;

Expand All @@ -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.
/// </summary>
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
Expand All @@ -33,6 +38,8 @@ public void ConfigureServices(IServiceCollection services)

// You can register additional message type and handler mappings here as well.
});

return builder;
}
}

Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading