Skip to content

Commit 784531d

Browse files
Update Messaging Processing Framework template project (#2020)
1 parent 83fb710 commit 784531d

File tree

5 files changed

+111
-10
lines changed

5 files changed

+111
-10
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.Templates",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Update the AWS Message Processing Framework for .NET project template."
8+
]
9+
}
10+
]
11+
}

Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/BlueprintBaseName.1.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
<PublishReadyToRun>true</PublishReadyToRun>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.6.1" />
14+
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.7.0" />
1515
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.0" />
1616
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
1717
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
18-
<PackageReference Include="AWS.Messaging.Lambda" Version="0.9.0" />
18+
<PackageReference Include="AWS.Messaging.Lambda" Version="0.10.1" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.3" />
1920
</ItemGroup>
2021
</Project>

Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Readme.md

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,95 @@ The framework reduces the amount of boiler-plate code developers need to write,
2020

2121
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.
2222

23-
## Testing Locally
23+
## Local Testing Guide
2424

25-
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.
25+
### Prerequisites
26+
The functions can be tested with the [Lambda Test Tool](https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool-v2).
27+
28+
1. Install the Lambda Test Tool:
29+
```bash
30+
dotnet tool install -g amazon.lambda.testtool
31+
```
32+
33+
2. Get the Lambda Test Tool version:
34+
35+
```
36+
dotnet lambda-test-tool info
37+
```
38+
39+
### Setup Steps
40+
41+
42+
1. Build the project
43+
44+
```
45+
dotnet build
46+
```
47+
48+
2. Start the Lambda Test Tool:
49+
50+
```
51+
dotnet lambda-test-tool start --lambda-emulator-port 5050
52+
```
53+
54+
3. Configure the project:
55+
* Update Properties/launchSettings.json with the Lambda Test Tool version and function handler name.
56+
57+
###$ Example launchSettings.json
58+
59+
```json
60+
{
61+
"profiles": {
62+
"Default": {
63+
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
64+
"commandName": "Executable",
65+
"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",
66+
"executablePath": "dotnet",
67+
"environmentVariables": {
68+
"AWS_LAMBDA_RUNTIME_API": "localhost:5050/MyFunction",
69+
"QUEUE_URL": "QUEUE_URL"
70+
}
71+
}
72+
}
73+
}
74+
75+
```
76+
77+
78+
### Running the project
79+
80+
### Option 1: Using Visual Studio
81+
1. Update launchSettings.json with the correct Lambda Test Tool version
82+
2. Run the project from Visual Studio
83+
84+
85+
### Option 2: Using Command Line
86+
87+
88+
```
89+
cd bin\Debug\net8.0
90+
$env:AWS_LAMBDA_RUNTIME_API = "localhost:5050/MyFunction"
91+
$env:VERSION = "0.9.1" // Use the version returned from dotnet lambda-test-tool info
92+
93+
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
94+
95+
96+
```
97+
98+
### Testing
99+
100+
The project includes sample payloads in 
101+
102+
```plaintext
103+
.lambda-test-tool\SavedRequests
104+
```
105+
106+
:
107+
108+
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`
109+
110+
2. "Handler Sample Request" - can be used to invoke the Handler function. This mocks the SQS message, and does not require an actual queue.
26111

27-
The project includes two sample payloads, one for each function handler.
28-
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`
29-
2. "Handler Sample Request" can be used to invoke the Handler function. This mocks the SQS message, and does not require an actual queue.
30112

31113
## Deploying and Testing from Visual Studio
32114

Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/Startup.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Amazon.Lambda.Annotations;
22
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Hosting;
34

45
namespace BlueprintBaseName._1;
56

@@ -14,10 +15,14 @@ public class Startup
1415
/// the lifetime of the Lambda compute container. Services injected as parameters are created within the scope
1516
/// of the function invocation.
1617
/// </summary>
17-
public void ConfigureServices(IServiceCollection services)
18+
public HostApplicationBuilder ConfigureHostBuilder()
1819
{
20+
21+
var builder = new HostApplicationBuilder();
22+
23+
1924
// Here we'll configure the AWS Message Processing Framework for .NET.
20-
services.AddAWSMessageBus(builder =>
25+
builder.Services.AddAWSMessageBus(builder =>
2126
{
2227
// Register that you'll publish messages of type "GreetingMessage" to the specified queue URL.
2328
// 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)
3338

3439
// You can register additional message type and handler mappings here as well.
3540
});
41+
42+
return builder;
3643
}
3744
}
3845

Blueprints/BlueprintDefinitions/vs2022/MessageProcessingFramework/template/src/BlueprintBaseName.1/serverless.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"AWSTemplateFormatVersion": "2010-09-09",
33
"Transform": "AWS::Serverless-2016-10-31",
4-
"Description": "AWS Message Processing Framework for .NET Template. This template is partially managed by Amazon.Lambda.Annotations (v1.6.1.0).",
4+
"Description": "AWS Message Processing Framework for .NET Template. This template is partially managed by Amazon.Lambda.Annotations (v1.7.0.0).",
55
"Resources": {
66
"MessageProcessingFrameworkDemoQueue": {
77
"Type": "AWS::SQS::Queue"

0 commit comments

Comments
 (0)