-
Notifications
You must be signed in to change notification settings - Fork 503
Improve Lambda Test Tool v2 getting-started docs and add samples #2494
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
Open
GarrettBeatty
wants to merge
7
commits into
dev
Choose a base branch
from
docs/testtool-v2-getting-started
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eb121ad
Improve Lambda Test Tool v2 getting-started docs and add samples
GarrettBeatty 203b4e1
Document CLI launch path for class-library functions
GarrettBeatty 1535a16
Address PR feedback: bump samples to net10, fix API GW mode and confi…
GarrettBeatty 4fb5b1e
Delete Tools/LambdaTestTool-v2/samples/AddFunctionClassLibrary/README.md
GarrettBeatty 63176c1
Delete Tools/LambdaTestTool-v2/samples/AddFunctionTopLevel/README.md
GarrettBeatty 6754d12
Delete Tools/LambdaTestTool-v2/samples/SQSProcessor/README.md
GarrettBeatty b9b5946
Delete Tools/LambdaTestTool-v2/samples/ToUpperFunction/README.md
GarrettBeatty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
Tools/LambdaTestTool-v2/samples/AddFunctionClassLibrary/AddFunctionClassLibrary.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <AWSProjectType>Lambda</AWSProjectType> | ||
| <AssemblyName>AddFunctionClassLibrary</AssemblyName> | ||
| <!-- Produces the .deps.json / .runtimeconfig.json the launch profile references. --> | ||
| <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
| <!-- Copy NuGet dependencies (Amazon.Lambda.Core, etc.) next to the output DLL so the | ||
| function can be launched from the command line without extra probing paths. --> | ||
| <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Amazon.Lambda.Core" Version="2.5.1" /> | ||
| <PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="3.0.0" /> | ||
| <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
20 changes: 20 additions & 0 deletions
20
Tools/LambdaTestTool-v2/samples/AddFunctionClassLibrary/Function.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using Amazon.Lambda.APIGatewayEvents; | ||
| using Amazon.Lambda.Core; | ||
|
|
||
| [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.CamelCaseLambdaJsonSerializer))] | ||
|
|
||
| namespace AddFunctionClassLibrary; | ||
|
|
||
| public class Function | ||
| { | ||
| /// <summary> | ||
| /// Adds the two path parameters {x} and {y} and returns the sum. | ||
| /// Handler string: AddFunctionClassLibrary::AddFunctionClassLibrary.Function::Add | ||
| /// </summary> | ||
| public int Add(APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) | ||
| { | ||
| var x = int.Parse(request.PathParameters["x"]); | ||
| var y = int.Parse(request.PathParameters["y"]); | ||
| return x + y; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
Tools/LambdaTestTool-v2/samples/AddFunctionClassLibrary/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "profiles": { | ||
| "LambdaTestTool": { | ||
| "commandName": "Executable", | ||
| "executablePath": "dotnet", | ||
| "workingDirectory": ".\\bin\\$(Configuration)\\net10.0", | ||
| "commandLineArgs": "exec --depsfile ./AddFunctionClassLibrary.deps.json --runtimeconfig ./AddFunctionClassLibrary.runtimeconfig.json %USERPROFILE%/.dotnet/tools/.store/amazon.lambda.testtool/{TEST_TOOL_VERSION}/amazon.lambda.testtool/{TEST_TOOL_VERSION}/content/Amazon.Lambda.RuntimeSupport/net10.0/Amazon.Lambda.RuntimeSupport.TestTool.dll AddFunctionClassLibrary::AddFunctionClassLibrary.Function::Add", | ||
| "environmentVariables": { | ||
| "AWS_LAMBDA_RUNTIME_API": "localhost:5050/AddLambdaFunction" | ||
| } | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
Tools/LambdaTestTool-v2/samples/AddFunctionTopLevel/AddFunctionTopLevel.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <AWSProjectType>Lambda</AWSProjectType> | ||
| <AssemblyName>AddFunctionTopLevel</AssemblyName> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Amazon.Lambda.Core" Version="2.5.1" /> | ||
| <PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="3.0.0" /> | ||
| <PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.13.0" /> | ||
| <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
17 changes: 17 additions & 0 deletions
17
Tools/LambdaTestTool-v2/samples/AddFunctionTopLevel/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using Amazon.Lambda.APIGatewayEvents; | ||
| using Amazon.Lambda.Core; | ||
| using Amazon.Lambda.RuntimeSupport; | ||
| using Amazon.Lambda.Serialization.SystemTextJson; | ||
|
|
||
| // Adds the two path parameters {x} and {y} and returns the sum. | ||
| // Uses the HTTP API v2 request shape, so run the API Gateway emulator in HttpV2 mode. | ||
| var handler = (APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context) => | ||
| { | ||
| var x = int.Parse(request.PathParameters["x"]); | ||
| var y = int.Parse(request.PathParameters["y"]); | ||
| return (x + y).ToString(); | ||
| }; | ||
|
|
||
| await LambdaBootstrapBuilder.Create(handler, new CamelCaseLambdaJsonSerializer()) | ||
| .Build() | ||
| .RunAsync(); |
10 changes: 10 additions & 0 deletions
10
Tools/LambdaTestTool-v2/samples/AddFunctionTopLevel/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "profiles": { | ||
| "AddLambdaFunction": { | ||
| "commandName": "Project", | ||
| "environmentVariables": { | ||
| "AWS_LAMBDA_RUNTIME_API": "localhost:5050/AddLambdaFunction" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Lambda Test Tool v2 — Sample Projects | ||
|
|
||
| Runnable starter functions for the [AWS Lambda Test Tool](../README.md). Each is a minimal, self-contained project with its own README and a ready-to-use launch profile. | ||
|
|
||
| | Sample | What it shows | Emulator setup | | ||
| |--------|---------------|----------------| | ||
| | [`AddFunctionTopLevel`](AddFunctionTopLevel) | Top-level-statements function behind the API Gateway emulator (the [Quick Start](../README.md#quick-start)). | Lambda + API Gateway (`HttpV2`) | | ||
| | [`AddFunctionClassLibrary`](AddFunctionClassLibrary) | A class-library function with a pre-filled `Executable` launch profile. | Lambda + API Gateway (`HttpV2`) | | ||
| | [`SQSProcessor`](SQSProcessor) | An `SQSEvent` handler, testable via the SQS event source or the built-in `sqs.json` sample event. | Lambda (+ optional SQS event source) | | ||
| | [`ToUpperFunction`](ToUpperFunction) | A minimal, zero-dependency function for exploring the web UI and sample events. | Lambda only | | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - .NET 10 SDK (the samples target `net10.0`). To build them with an older SDK, change `<TargetFramework>` to `net8.0` or `net9.0`. | ||
| - The test tool installed: `dotnet tool install -g amazon.lambda.testtool` (see the [main README](../README.md#prerequisites)). | ||
|
|
||
| Start with [`AddFunctionTopLevel`](AddFunctionTopLevel) if you're new — it's the lowest-friction path from install to a working invocation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Amazon.Lambda.Core; | ||
| using Amazon.Lambda.RuntimeSupport; | ||
| using Amazon.Lambda.Serialization.SystemTextJson; | ||
| using Amazon.Lambda.SQSEvents; | ||
|
|
||
| // Processes a batch of SQS messages, logging each message body. | ||
| // Test it either with the built-in "sqs.json" sample event from the web UI, | ||
| // or by wiring a real queue with --sqs-eventsource-config (see this sample's README). | ||
| var handler = (SQSEvent evnt, ILambdaContext context) => | ||
| { | ||
| foreach (var message in evnt.Records) | ||
| { | ||
| context.Logger.LogLine($"Processing message {message.MessageId}: {message.Body}"); | ||
| } | ||
|
|
||
| context.Logger.LogLine($"Processed {evnt.Records.Count} message(s)."); | ||
| }; | ||
|
|
||
| await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer()) | ||
| .Build() | ||
| .RunAsync(); |
10 changes: 10 additions & 0 deletions
10
Tools/LambdaTestTool-v2/samples/SQSProcessor/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "profiles": { | ||
| "SQSProcessor": { | ||
| "commandName": "Project", | ||
| "environmentVariables": { | ||
| "AWS_LAMBDA_RUNTIME_API": "localhost:5050/SQSProcessor" | ||
| } | ||
| } | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
Tools/LambdaTestTool-v2/samples/SQSProcessor/SQSProcessor.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <AWSProjectType>Lambda</AWSProjectType> | ||
| <AssemblyName>SQSProcessor</AssemblyName> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Amazon.Lambda.Core" Version="2.5.1" /> | ||
| <PackageReference Include="Amazon.Lambda.SQSEvents" Version="3.0.0" /> | ||
| <PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.13.0" /> | ||
| <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
21 changes: 21 additions & 0 deletions
21
Tools/LambdaTestTool-v2/samples/ToUpperFunction/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Amazon.Lambda.Core; | ||
| using Amazon.Lambda.RuntimeSupport; | ||
| using Amazon.Lambda.Serialization.SystemTextJson; | ||
|
|
||
| // A minimal function: uppercases the input string. | ||
| // Send the string "error" to see how the tool renders a thrown exception. | ||
| var handler = (string input, ILambdaContext context) => | ||
| { | ||
| context.Logger.LogLine($"Executing function with input: {input}"); | ||
|
|
||
| if (string.Equals("error", input, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| throw new Exception("Forced error to demonstrate error rendering."); | ||
| } | ||
|
|
||
| return input?.ToUpper(); | ||
| }; | ||
|
|
||
| await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer()) | ||
| .Build() | ||
| .RunAsync(); |
10 changes: 10 additions & 0 deletions
10
Tools/LambdaTestTool-v2/samples/ToUpperFunction/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "profiles": { | ||
| "ToUpperFunction": { | ||
| "commandName": "Project", | ||
| "environmentVariables": { | ||
| "AWS_LAMBDA_RUNTIME_API": "localhost:5050/ToUpperFunction" | ||
| } | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
Tools/LambdaTestTool-v2/samples/ToUpperFunction/ToUpperFunction.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <AWSProjectType>Lambda</AWSProjectType> | ||
| <AssemblyName>ToUpperFunction</AssemblyName> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Amazon.Lambda.Core" Version="2.5.1" /> | ||
| <PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.13.0" /> | ||
| <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.4" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.