Skip to content

Commit 23b3252

Browse files
committed
Update README.md for .NET Core Lambda Test Tool
1 parent 4c38fb6 commit 23b3252

File tree

3 files changed

+95
-19
lines changed

3 files changed

+95
-19
lines changed

Tools/LambdaTestTool/README.md

Lines changed: 90 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,113 @@ The AWS .NET Mock Lambda Test Tool is a tool that can be used to load a .NET Cor
1414
- [Configure for Visual Studio for Mac](#configure-for-visual-studio-for-mac)
1515
- [Known Limitations](#known-limitations)
1616

17-
## Getting Help
17+
## Getting help
1818

1919
This tool is currently in preview and there are some known limitations. For questions and problems please open a GitHub issue in this repository.
2020

21+
## Versions of the tool
22+
23+
There are separate versions of this tool for each support .NET Core Lambda runtime. Currently there are too supported versions .NET Core 2.1
24+
and .NET Core 3.1. When using the AWS [AWS Toolkit for Visual Studio](https://marketplace.visualstudio.com/items?itemName=AmazonWebServices.AWSToolkitforVisualStudio2017)
25+
26+
27+
|.NET Core Version | Tool NuGet Package | Tool executable|
28+
|------------------|--------------------|----------------|
29+
| .NET Core 2.1 | Amazon.Lambda.TestTool-2.1 | dotnet-lambda-test-tool-2.1.exe |
30+
| .NET Core 3.1 | Amazon.Lambda.TestTool-3.1 | dotnet-lambda-test-tool-3.1.exe |
31+
2132
## AWS Credentials
2233

23-
In the Lambda environment an IAM Role is assigned to the function that delivers AWS Credentials to the Lambda compute environment. When service clients from the AWS SDK for .NET are created without explicit credentials the SDK will search the running environment for credentials and find the credentials delivered by the IAM role.
34+
In the Lambda environment an IAM Role is assigned to the function that delivers AWS Credentials to the Lambda compute environment. When
35+
service clients from the AWS SDK for .NET are created without explicit credentials the SDK will search the running environment for
36+
credentials and find the credentials delivered by the IAM role.
2437

25-
IAM Roles are **not** used with this tool. Instead a credential profile is selected from the host machine's credential before the code is run. The **AWS_PROFILE** environment variable is set to the selected profile. Just like in the Lambda environment when a service client is created without explicit credentials the SDK searches for credentials and will find the AWS_PROFILE environment variable and retrieve the credentials from the local credential file.
38+
IAM Roles are **not** used with this tool. Instead a credential profile is selected from the host machine's credential before the code is
39+
run. The **AWS_PROFILE** environment variable is set to the selected profile. Just like in the Lambda environment when a service client
40+
is created without explicit credentials the SDK searches for credentials and will find the AWS_PROFILE environment variable and retrieve the
41+
credentials from the local credential file.
2642

27-
## Installing and Running
43+
## Installing and running
2844

29-
The tool is distributed as a .NET Global Tool via the NuGet package Amazon.Lambda.TestTool-2.1. To install the tool execute the following command:
45+
The tool is distributed as .NET Global Tools via the NuGet packages. There is a package for each Lambda runtime supported which the table above describes.
46+
The suffix of each package indicates the version of .NET Core the package is for. To install the tool execute the following command:
3047

3148
```
32-
dotnet tool install -g Amazon.Lambda.TestTool-2.1
49+
dotnet tool install -g Amazon.Lambda.TestTool-3.1
3350
```
3451

3552
To update the tool run the following command:
3653

3754
```
38-
dotnet tool update -g Amazon.Lambda.TestTool-2.1
55+
dotnet tool update -g Amazon.Lambda.TestTool-3.1
3956
```
4057

4158
The main intention for this tool is to make it easy to debug .NET Core Lambda code from an IDE. The tool can be run without an IDE by executing the following command from the project directory. The .NET Core Lambda project **must be built for debug** before running this tool. It doesn't do this automatically because it is assumed an IDE will have built the project before executing this program.
4259

4360
```
44-
dotnet lambda-test-tool-2.1
61+
dotnet lambda-test-tool-3.1
4562
```
4663

64+
## Skip using the web interface
65+
66+
In the default mode this tool uses the web interface to select the .NET Lambda code to run. It is also possible to skip using the web interface and identify the .NET Lambda code to run
67+
using command line arguments. The key command line argument to set is <b>--no-ui</b> which will turn off the web interface. Using the <b>--help</b> command line argument you can see the list of
68+
arguments that can be used to identify the .NET Lambda code and set environment settings like aws profile and region as well as a payload JSON document to be used as the function input.
69+
70+
<pre style="white-space: pre-wrap; background-color:lightgray;font-size:85%">
71+
&gt; dotnet lambda-test-tool-3.1 --help
72+
AWS .NET Core 3.1 Mock Lambda Test Tool (0.10.0)
73+
74+
The .NET Lambda Test Tool can be launched in 2 modes. The default mode is to launch a web interface to select the Lambda code
75+
to execute with in the Lambda test tool. The second mode skips using the web interface and the Lambda code is identified
76+
using the commandline switches as described below. To switch to the no web interface mode use the --no-ui command line switch.
77+
78+
These options are valid for either mode the Lambda test tool is running in.
79+
80+
--path &lt;directory&gt; The path to the lambda project to execute. If not set then the current directory will be used.
81+
82+
These options are valid when using the web interface to select and execute the Lambda code.
4783

48-
### Why the 2.1 Suffix?
84+
--port &lt;port-number&gt; The port number used for the test tool's web interface.
85+
--no-launch-window Disable auto launching the test tool's web interface in a browser.
4986

50-
Since this tool loads .NET Core Lambda code within its process the version of .NET Core must match the target Lambda Runtime, which is .NET Core 2.1 in this case. When future .NET Core Lambda environments become available a new NuGet package will be released with the suffix updated to match the target framework.
87+
These options are valid in the no web interface mode.
5188

89+
--no-ui Disable launching the web interface and immediately execute the Lambda code.
90+
--profile &lt;profile-name&gt; Set the AWS credentials profile to provide credentials to the Lambda code.
91+
If not set the profile from the config file will be used.
92+
--region &lt;region-name&gt; Set the AWS region to as the default region for the Lambda code being executed.
93+
If not set the region from the config file will be used.
94+
--config-file &lt;file-name&gt; The config file to read for Lambda settings. If not set than aws-lambda-tools-defaults.json
95+
will be used.
96+
--function-handler &lt;handler-string&gt; The Lambda function handler to identify the code to run. If not set then the function handler
97+
from the config file will be used. This is the format of &lt;assembly::type-name::method-name&gt;.
98+
--payload &lt;file-name&gt; The JSON payload to send to the Lambda function. This can be either an inline string or a
99+
file path to a JSON file.
100+
--pause-exit &lt;true or false&gt; If set to true the test tool will pause waiting for a key input before exiting. The is useful
101+
when executing from an IDE so you can avoid having the output window immediately disappear after
102+
executing the Lambda code. The default value is true.
103+
</pre>
104+
105+
For command line arguments not set the defaults and config file will be used to determine the .NET Lambda code to run. For example if you just use the <b>--no-ui</b> argument then the
106+
<b>aws-lambda-tools-defaults.json</b> will be searched for and used if found. The tool when then use the function handler, profile and region specified in the configuration file to run
107+
.NET Lambda code.
108+
109+
Here is an example of a <b>launchSettings.json</b> file configured to use this tool without the web interface. Only <b>--no-ui</b> and <b>--payload</b> are set turning off the web interface
110+
and indicating the contents of the payload.json file should be used as the function input. The function handler is identified from the project's <b>aws-lambda-tools-defaults.json</b> file.
111+
112+
<pre style="white-space: pre-wrap; background-color:lightgray;font-size:85%">
113+
{
114+
"profiles": {
115+
"Mock Lambda Test Tool": {
116+
"commandName": "Executable",
117+
"commandLineArgs": "--no-ui --payload payload.json",
118+
"workingDirectory": ".\\bin\\$(Configuration)\\netcoreapp3.1",
119+
"executablePath": "C:\\Users\\%USERNAME%\\.dotnet\\tools\\dotnet-lambda-test-tool-3.1.exe"
120+
}
121+
}
122+
}
123+
</pre>
52124

53125
## Configure for Visual Studio
54126

@@ -61,8 +133,8 @@ When a project is opened in Visual Studio the toolkit will detect the project is
61133
"Mock Lambda Test Tool": {
62134
"commandName": "Executable",
63135
"commandLineArgs": "--port 5050",
64-
"executablePath": "<home-directory>\\.dotnet\\tools\\dotnet-lambda-test-tool-2.1.exe",
65-
"workingDirectory": ".\\bin\\Debug\\netcoreapp2.1"
136+
"executablePath": "<home-directory>\\.dotnet\\tools\\dotnet-lambda-test-tool-3.1.exe",
137+
"workingDirectory": ".\\bin\\Debug\\netcoreapp3.1"
66138
}
67139
}
68140
}
@@ -73,7 +145,7 @@ When a project is opened in Visual Studio the toolkit will detect the project is
73145

74146
Before using Visual Studio Code you must follow the instructions above on installing the .NET Mock Lambda Test Tool.
75147

76-
To debug with Visual Studio Code and the .NET Mock Lambda Test Tool edit the [launch.json](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) configuration file and have the `program` property point to `dotnet-lambda-test-tool-2.1.exe` and make sure `cwd` is pointing the .NET Core Lambda project. Note that on a non-windows environment the executable will be called `dotnet-lambda-test-tool-2.1` without the ".exe" at the end. The `dotnet-lambda-test-tool-2.1.exe` executable can be found in the `.dotnet/tools` directory under your home directory. Depending on your file system settings, the `.dotnet` directory can appear hidden.
148+
To debug with Visual Studio Code and the .NET Mock Lambda Test Tool edit the [launch.json](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) configuration file and have the `program` property point to `dotnet-lambda-test-tool-.1.exe` and make sure `cwd` is pointing the .NET Core Lambda project. Note that on a non-windows environment the executable will be called `dotnet-lambda-test-tool-3.1` without the ".exe" at the end. The `dotnet-lambda-test-tool-3.1.exe` executable can be found in the `.dotnet/tools` directory under your home directory. Depending on your file system settings, the `.dotnet` directory can appear hidden.
77149

78150
```json
79151
{
@@ -84,7 +156,7 @@ To debug with Visual Studio Code and the .NET Mock Lambda Test Tool edit the [la
84156
"type": "coreclr",
85157
"request": "launch",
86158
"preLaunchTask": "build",
87-
"program": "<home-directory>/.dotnet/tools/dotnet-lambda-test-tool-2.1.exe",
159+
"program": "<home-directory>/.dotnet/tools/dotnet-lambda-test-tool-3.1.exe",
88160
"args": [],
89161
"cwd": "${workspaceFolder}",
90162
"console": "internalConsole",
@@ -105,10 +177,10 @@ To customize the launch behavior for the debugger, you can pass additional argum
105177

106178
Before using JetBrains Rider you must follow the instructions above on installing the .NET Mock Lambda Test Tool.
107179

108-
Configuring Rider to use the .NET Mock Lambda Test Tool is a little different compared to Visual Studio. For Rider the executable target needs to be the main assembly `Amazon.Lambda.TestTool.dll` for the Test Tool and **not** the Global Tool executable `dotnet-lambda-test-tool-2.1`. The path to `Amazon.Lambda.TestTool.dll` is:
180+
Configuring Rider to use the .NET Mock Lambda Test Tool is a little different compared to Visual Studio. For Rider the executable target needs to be the main assembly `Amazon.Lambda.TestTool.dll` for the Test Tool and **not** the Global Tool executable `dotnet-lambda-test-tool-3.1`. The path to `Amazon.Lambda.TestTool.dll` is:
109181

110182
```
111-
<home-directory>/.dotnet/tools/.store/amazon.lambda.testtool-2.1/<nuget-version>/amazon.lambda.testtool-2.1/<nuget-version>/tools/netcoreapp2.1/any/Amazon.Lambda.TestTool.dll
183+
<home-directory>/.dotnet/tools/.store/amazon.lambda.testtool-3.1/<nuget-version>/amazon.lambda.testtool-3.1/<nuget-version>/tools/netcoreapp3.1/any/Amazon.Lambda.TestTool.dll
112184
```
113185

114186
Remember when you update your version of the .NET Mock Lambda Test Tool to update the nuget versions numbers in this path string for your IDE's configuration.
@@ -128,10 +200,10 @@ After following these steps, any time you start the debugger in Rider, it will s
128200

129201
Before using Visual Studio for Mac you must follow the instructions above on installing the .NET Mock Lambda Test Tool.
130202

131-
Configuring Visual Studio for Mac to use the .NET Mock Lambda Test Tool is a little different compared to Visual Studio. For Visual Studio for Mac the executable target needs to be the main assembly `Amazon.Lambda.TestTool.dll` for the Test Tool and **not** the Global Tool executable `dotnet-lambda-test-tool-2.1`. The path to `Amazon.Lambda.TestTool.dll` is:
203+
Configuring Visual Studio for Mac to use the .NET Mock Lambda Test Tool is a little different compared to Visual Studio. For Visual Studio for Mac the executable target needs to be the main assembly `Amazon.Lambda.TestTool.dll` for the Test Tool and **not** the Global Tool executable `dotnet-lambda-test-tool-3.1`. The path to `Amazon.Lambda.TestTool.dll` is:
132204

133205
```
134-
<home-directory>/.dotnet/tools/.store/amazon.lambda.testtool-2.1/<nuget-version>/amazon.lambda.testtool-2.1/<nuget-version>/tools/netcoreapp2.1/any/Amazon.Lambda.TestTool.dll
206+
<home-directory>/.dotnet/tools/.store/amazon.lambda.testtool-3.1/<nuget-version>/amazon.lambda.testtool-3.1/<nuget-version>/tools/netcoreapp3.1/any/Amazon.Lambda.TestTool.dll
135207
```
136208
Remember when you update your version of the .NET Mock Lambda Test Tool to update the nuget versions numbers in this path string for your IDE's configuration.
137209

@@ -148,6 +220,5 @@ Once this is done when you start the debugger in Visual Studio for Mac it will l
148220

149221
## Known Limitations
150222

151-
* YAML based CloudFormation templates are not yet supported.
152223
* No mechanism for setting custom Environment variables.
153224
* NuGet packages that use native dependencies are not supported.
-79.1 KB
Loading

Tools/LambdaTestTool/aws-lambda-test-tool-netcore.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.TestTool.Test
4949
EndProject
5050
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Amazon.Lambda.TestTool.Tests.NETCore31", "tests\Amazon.Lambda.TestTool.Tests.NETCore31\Amazon.Lambda.TestTool.Tests.NETCore31.csproj", "{E57ABB02-E8FC-4011-95D3-E9CB9412EDCB}"
5151
EndProject
52+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B0304AF-C6CF-4B62-B1B3-3F7C045B1BC4}"
53+
ProjectSection(SolutionItems) = preProject
54+
README.md = README.md
55+
EndProjectSection
56+
EndProject
5257
Global
5358
GlobalSection(SharedMSBuildProjectFiles) = preSolution
5459
tests\Amazon.Lambda.TestTool.Tests.Shared\Amazon.Lambda.TestTool.Tests.Shared.projitems*{594ee68c-10c0-4a19-9b61-377d0ab2f5ed}*SharedItemsImports = 5

0 commit comments

Comments
 (0)