Skip to content

Commit 6d1fe2f

Browse files
Merge pull request #200 from awslabs/gcbeatty/merge
2 parents 2e6aed9 + e590fe2 commit 6d1fe2f

File tree

20 files changed

+773
-55
lines changed

20 files changed

+773
-55
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": "AWS.Messaging",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Update error message for handling scenario where subscriber mapping is not valid."
8+
]
9+
}
10+
]
11+
}

.github/workflows/doc-site.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,33 @@ permissions:
1717
concurrency:
1818
group: "pages"
1919
cancel-in-progress: false
20-
20+
2121
jobs:
2222
publish-docs:
2323
environment:
2424
name: github-pages
2525
url: ${{ steps.deployment.outputs.page_url }}
2626
runs-on: ubuntu-latest
2727
steps:
28-
- name: Checkout
29-
uses: actions/checkout@v3
30-
- name: Dotnet Setup
31-
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # pinning V4
32-
with:
33-
dotnet-version: 8.x
34-
35-
- run: dotnet tool update -g docfx --version 2.74.0
36-
- run: docfx docs/docfx.json
37-
38-
- name: Setup Pages
39-
uses: actions/configure-pages@v3
40-
- name: Upload artifact
41-
uses: actions/upload-pages-artifact@v2
42-
with:
43-
# Upload entire repository
44-
path: 'docs/_site'
45-
- name: Deploy to GitHub Pages
46-
id: deployment
47-
uses: actions/deploy-pages@v2
28+
- name: Checkout
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pinning V4
30+
- name: Dotnet Setup
31+
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # pinning V4
32+
with:
33+
dotnet-version: 8.x
34+
35+
- run: dotnet tool update -g docfx --version 2.78.3
36+
- run: docfx docs/docfx.json
37+
38+
- name: Setup Pages
39+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # pinning V5
40+
- name: Upload artifact
41+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # pinning V3
42+
with:
43+
# Upload entire repository
44+
path: "docs/_site"
45+
- name: Deploy to GitHub Pages
46+
id: deployment
47+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # pinning V4
48+
49+

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Release 2025-03-12
2+
3+
### AWS.Messaging (0.9.5)
4+
* Update error message for handling scenario where subscriber mapping is not valid.
5+
16
## Release 2025-02-20
27

38
### AWS.Messaging (0.9.4)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"Records": [
3+
{
4+
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78",
5+
"receiptHandle": "MessageReceiptHandle",
6+
"body": "{\"id\":\"d9b4bfc7-9398-44aa-8049-85c07490fb35\",\"source\":\"/AWSLambda/FunctionName\",\"specversion\":\"1.0\",\"type\":\"chatMessage\",\"time\":\"2024-03-22T21:01:03.5484607+00:00\",\"data\":\"{\\u0022MessageDescription\\u0022:\\u0022Testing!!!\\u0022}\"}",
7+
"attributes": {
8+
"ApproximateReceiveCount": "1",
9+
"SentTimestamp": "1523232000000",
10+
"SenderId": "123456789012",
11+
"ApproximateFirstReceiveTimestamp": "1523232000001"
12+
},
13+
"messageAttributes": {},
14+
"md5OfBody": "7b270e59b47ff90a553787216d55d91d",
15+
"eventSource": "aws:sqs",
16+
"eventSourceARN": "arn:{partition}:sqs:{region}:123456789012:MyQueue",
17+
"awsRegion": "{region}"
18+
}
19+
]
20+
}

sampleapps/LambdaMessaging/LambdaMessaging.csproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
<Nullable>enable</Nullable>
66
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
77
<AWSProjectType>Lambda</AWSProjectType>
8-
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. -->
98
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
109
<!-- Generate ready to run images during publishing to improve cold start time. -->
1110
<PublishReadyToRun>true</PublishReadyToRun>
1211
</PropertyGroup>
1312
<ItemGroup>
14-
<PackageReference Include="Amazon.Lambda.Core" Version="2.5.1" />
15-
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" />
16-
<PackageReference Include="Amazon.Lambda.SQSEvents" Version="2.2.0" />
1713
<PackageReference Include="Amazon.Lambda.Annotations" Version="1.7.0" />
18-
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="3.1.1" />
19-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.*" />
14+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.0" />
15+
<PackageReference Include="Amazon.Lambda.Logging.AspNetCore" Version="3.1.0" />
16+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
2017
</ItemGroup>
2118
<ItemGroup>
2219
<ProjectReference Include="..\..\src\AWS.Messaging.Lambda\AWS.Messaging.Lambda.csproj" />
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"profiles": {
3-
"Mock Lambda Test Tool": {
4-
"commandName": "Executable",
5-
"commandLineArgs": "--port 5050",
3+
"Default": {
64
"workingDirectory": ".\\bin\\$(Configuration)\\net8.0",
7-
"executablePath": "%USERPROFILE%\\.dotnet\\tools\\dotnet-lambda-test-tool-8.0.exe"
5+
"commandName": "Executable",
6+
"commandLineArgs": "exec --depsfile ./LambdaMessaging.deps.json --runtimeconfig ./LambdaMessaging.runtimeconfig.json %USERPROFILE%/.dotnet/tools/.store/amazon.lambda.testtool/${VERSION}/amazon.lambda.testtool/${VERSION}/content/Amazon.Lambda.RuntimeSupport/net8.0/Amazon.Lambda.RuntimeSupport.dll LambdaMessaging::LambdaMessaging.Function_FunctionHandler_Generated::FunctionHandler",
7+
"executablePath": "dotnet",
8+
"environmentVariables": {
9+
"AWS_LAMBDA_RUNTIME_API": "localhost:5050/MyFunction"
10+
}
811
}
912
}
10-
}
13+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Lambda Messaging Sample Application
2+
3+
This sample application demonstrates how to use AWS Lambda with the AWS Message Processing Framework for .NET to process messages from SQS queues.
4+
5+
## Overview
6+
7+
This sample shows how to:
8+
- Configure a Lambda function to process messages from SQS
9+
- Use dependency injection with Lambda Annotations
10+
- Handle message batch processing
11+
- Implement partial batch failure responses
12+
- Set up message handlers for specific message types
13+
14+
## Prerequisites
15+
16+
- .NET 8.0 or later
17+
18+
19+
## Project Structure
20+
21+
```
22+
LambdaMessaging/
23+
├── Function.cs # Lambda function handler
24+
├── Startup.cs # DI and service configuration
25+
├── ChatMessage.cs # Message type definition
26+
├── ChatMessageHandler.cs # Message handler implementation
27+
├── LambdaMessaging.csproj # Project file
28+
```
29+
30+
31+
## Getting Started
32+
33+
In order to test the lambda function locally with the messaging processing framework, it requires installing the Lambda Test Tool https://github.com/aws/aws-lambda-dotnet/blob/master/Tools/LambdaTestTool-v2 first.
34+
35+
1. Build the project
36+
37+
```
38+
dotnet build
39+
```
40+
41+
2Install the AWS Lambda Test Tool:
42+
```bash
43+
dotnet tool install -g amazon.lambda.testtool
44+
```
45+
46+
3. Start the Lambda Test Tool:
47+
48+
```bash
49+
dotnet lambda-test-tool start --lambda-emulator-port 5050
50+
```
51+
52+
4. Get the test tool version:
53+
54+
```
55+
dotnet lambda-test-tool info
56+
```
57+
58+
5. Run the `LambdaMessaging` project.
59+
60+
There are 2 ways to run it
61+
1. Visual studio (easiest way).
62+
1a. Update `Properties/launchSettings.json` and replace `${VERSIOMN} with the actual test tool version.
63+
2. Via command line
64+
65+
```
66+
cd bin\Debug\net8.0
67+
$env:AWS_LAMBDA_RUNTIME_API = "localhost:5050/MyFunction"
68+
$env:VERSION = "0.9.1" // Use the version returned from dotnet lambda-test-tool info
69+
70+
dotnet exec --depsfile ./LambdaMessaging.deps.json --runtimeconfig ./LambdaMessaging.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" LambdaMessaging::LambdaMessaging.Function_FunctionHandler_Generated::FunctionHandler
71+
72+
73+
```
74+
75+
6. You should now see the `MyFunction` appear in the test tools function list drop down in the top right corner. Select `MyFunction`.
76+
77+
7. We have provided a `HandlerSampleRequest.json` file to be used to test this function. Copy and paste this json into the test tools input window and then hit the "invoke button".
78+
79+
8. You should see in the console window that the `ChatMessageHandler` successfully processed the message. There should be a log statement saying `Message Description: Testing!!!`.
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
using Amazon.Lambda.Annotations;
22
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Hosting;
34
using Microsoft.Extensions.Logging;
45

56
namespace LambdaMessaging;
67

78
[LambdaStartup]
89
public class Startup
910
{
10-
public void ConfigureServices(IServiceCollection services)
11+
public HostApplicationBuilder ConfigureHostBuilder()
1112
{
12-
services.AddLogging(builder =>
13+
var builder = new HostApplicationBuilder();
14+
builder.Services.AddLogging(b =>
1315
{
14-
builder.SetMinimumLevel(LogLevel.Trace);
15-
builder.AddLambdaLogger();
16+
b.SetMinimumLevel(LogLevel.Trace);
17+
b.AddLambdaLogger();
1618
});
17-
services.AddAWSMessageBus(builder =>
19+
builder.Services.AddAWSMessageBus(b =>
1820
{
19-
builder.AddMessageHandler<ChatMessageHandler, ChatMessage>("chatMessage");
21+
b.AddMessageHandler<ChatMessageHandler, ChatMessage>("chatMessage");
2022

21-
builder.AddLambdaMessageProcessor(options =>
23+
b.AddLambdaMessageProcessor(options =>
2224
{
2325
options.MaxNumberOfConcurrentMessages = 2;
2426
});
2527
});
28+
29+
return builder;
2630
}
2731
}

sampleapps/PollyIntegration/PollyIntegration.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.*" />
22-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.*" />
21+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.3" />
22+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
2323
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" />
2424
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
2525
<PackageReference Include="Polly.Core" Version="8.1.0" />

0 commit comments

Comments
 (0)