|
| 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!!!`. |
0 commit comments