Date:

Share:

How To Set Up AWS .NET Mock Lambda Test Tool on JetBrains Rider

Related Articles

This article is sponsored by AWS and is part of my AWS series.

God AWS .NET Mock Lambda Tool Test Used to test and debug AWS Lambda functions on your local development machine.

Based on the IDE you use for your development, you can attach it to the lambda testing tool and debug and step through the function code. When using Visual Studio, the default Lambda Function template has everything configured and ready to use with the Lambda testing tool.

However, this is not the case if you use JetBrains Rider.

In this post, let’s quickly learn how to configure JetBrains Rrider to work with the .NET Mock Lambda testing tool.

The Mock Lambda tool helps test the Lambda function locally without deploying it in an AWS environment.

📢

Note: This tool is not a local lambda environment. This tool is optimized for fast local debugging with minimal dependencies.

The tool is available as a global .NET tool and can be installed via the command line from NuGet. You can find additional installation instructions Here.

dotnet tool install -g Amazon.Lambda.TestTool-6.0

You can find the official instructions for setting up the simulated lambda test tool with JetBrains Rider Here.

We’ll see two different ways to configure the Mock Lambda testing tool to work with Rider.

Using the .run Rider file

JetBrains Rider uses Run/debug configurations To run, debug, deploy and test your code. Each configuration is a named set of session properties that define what to do and what parameters and environment to use.

  1. Add a new configuration
  2. Select .NET Executable Configuration Type as shown below

3. Specify the ‘Exe path’ for the configuration → this is the path to the Mock Lambda Test Tool global dll (Amazon.Lambda.TestTool.BlazorTester.dll).
You can find the DLL at /.dotnet/tools The folder where the global tools are installed.

4. Specify the working directory → This is the root of the AWS Lambda function project.

Clicking Apply and running the project with the new configuration launches and attaches Rider to the Mock Lambda testing tool for debugging.

Save the configuration in source control

To save the configuration file as a project file, you can select the Store as project file option, when creating the startup/debug configuration.

This will save the configuration to a file in the solution and can be checked into source control so that it is available to all team members using JetBrains Rider.

Below is an example run.xml A file with the configuration of the Mock Lambda Test tool.

Since it uses a path relative to the mock test tool for .NET and the project folder, it will work fine on any computer as long as they have the mock tool installed.

<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="Mock Lambda Test Tool" type="RunExe" factoryName=".NET Executable">
    <option name="EXE_PATH" value="$USER_HOME$/.dotnet/tools/.store/amazon.lambda.testtool-6.0/0.12.2/amazon.lambda.testtool-6.0/0.12.2/tools/net6.0/any/Amazon.Lambda.TestTool.BlazorTester.dll" />
    <option name="PROGRAM_PARAMETERS" value="" />
    <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Rider.lambda/src/Rider.lambda/" />
    <option name="PASS_PARENT_ENVS" value="1" />
    <option name="USE_EXTERNAL_CONSOLE" value="0" />
    <option name="USE_MONO" value="0" />
    <option name="RUNTIME_ARGUMENTS" value="" />
    <method v="2">
      <option name="Build Solution" enabled="true" />
    </method>
  </configuration>
</component>

Using the launchsettings.json file

Visual Studio by default uses launcsettings.json A file to store the running/debugging configuration of the labda mock test tool.

Below are the default settings when creating an AWS Lambda project in Visual Studio.

{
  "profiles": {
    "Mock Lambda Test Tool": {
      "commandName": "Executable",
      "commandLineArgs": "--port 5050",
      "workingDirectory": ".\bin\$(Configuration)\net6.0",
      "executablePath": "%USERPROFILE%\.dotnet\tools\dotnet-lambda-test-tool-6.0.exe"
    }
  }
}

This automatically configures the .NET Mock Lambda Test tool and runs automatically as soon as you run the application.

However, the same configuration does not work with JetBrains Rider.

However, we can modify it a bit (or add a new profile) to work with JetBrains Rider.

instead of running the dotnet-lambda-test-tool-6.0.exe Directly, we can run it as a dotnet application just like we configured the .NET startup/debugging configuration in the previous method.

{
  "profiles": {
    "Mock Lambda Test Tool (Rider)": {
      "commandName": "Executable",
      "commandLineArgs": "%USERPROFILE%/.dotnet/tools/.store/amazon.lambda.testtool-6.0/0.12.2/amazon.lambda.testtool-6.0/0.12.2/tools/net6.0/any/Amazon.Lambda.TestTool.BlazorTester.dll --port 5050",
      "workingDirectory": "$(ProjectDir)",
      "executablePath": "dotnet"
    }
  }
}

The profile above uses dotnet executable file and runs the test tool Mock Lamba ( Amazon.Lambda.TestTool.BlazorTester.dll) on port 5050.

Selecting this profile in Rider and running the application also runs the Mock Lambda Test tool and attaches the debugger to the application code.

⚠️

Remember to update the NuGet version numbers in the path when you update your version of the .NET Mock Lambda Test tool.

The same profile also works with Visual Studio. You can choose to use the same or have two profiles – one for Visual Studio and one for Rider.

Source

Popular Articles