Deployment Integrations
On-premise Integrations
Platform Integrations

Integration Options

Serverless Framework
AWS SAM
AWS CDK
Programmatic Configuration
Serverless Framework

Step 1: Add Thundra NuGet package

The .NET Thundra agent can simply be downloaded with the command below:

dotnet add package Thundra.Agent.Lambda --version $LATEST_VERSION
Latest version

Similarly, including agent can be done via the NuGet Package Manager of your IDE if it is available. For example, Visual Studio allows you to add packages through the IDE itself, and a simple search of Thundra .NET will allow you to procure the correct agent to be added to your project.

Step 2: Change serverless.yml

You should replace all your handler to “Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle” and give the real handler path as environment variable separately.

serverless.yml
...
functions:
FirstFunction:
handler: Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle
environment:
thundra_agent_lambda_handler: <your_handler>
thundra_apiKey: <your_api_key>
SecondFunction:
handler: Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle
environment:
thundra_agent_lambda_handler: <your_second_handler>
thundra_apiKey: <your_api_key>
...

Thanks to this method, you can connect Thundra to your functions by modifying the configuration files without changing code. The ThundraProxy class will call the actual handler as soon as it receives the request.

AWS SAM

Step 1: Add Thundra NuGet package

The .NET Thundra agent can simply be downloaded with the command below:

dotnet add package Thundra.Agent.Lambda --version $LATEST_VERSION
Latest version

Similarly, including agent can be done via the NuGet Package Manager of your IDE if it is available. For example, Visual Studio allows you to add packages through the IDE itself, and a simple search of Thundra .NET will allow you to procure the correct agent to be added to your project.

Step 2: Change template.yaml

You should replace all your handler to “Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle” and give the real handler path as environment variable separately.

template.yaml
....
FirstFunction:
Type: AWS::Serverless::Function
Properties:
Handler: Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle
Environment:
Variables:
thundra_agent_lambda_handler: <your_handler>
thundra_apiKey: <your_api_key>
SecondFunction:
Type: AWS::Serverless::Function
Properties:
Handler: Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle
Environment:
Variables:
thundra_agent_lambda_handler: <your_second_handler>
thundra_apiKey: <your_api_key>
...

Thanks to this method, you can connect Thundra to your functions by modifying the configuration files without changing code. The ThundraProxy class will call the actual handler as soon as it receives the request.

AWS CDK

AWS CDK

Step 1: Add Thundra NuGet package to your lambda

The .NET Thundra agent can simply be downloaded with the command below:

dotnet add package Thundra.Agent.Lambda --version $LATEST_VERSION
Latest version

Similarly, including agent can be done via the NuGet Package Manager of your IDE if it is available. For example, Visual Studio allows you to add packages through the IDE itself, and a simple search of Thundra .NET will allow you to procure the correct agent to be added to your project.

Step 2: Apply configuration changes on your function properties.

  • Add thundra_apiKey environment variable with your thundra api key.

using Amazon.CDK;
using Amazon.CDK.AWS.Lambda;
using System.Collections.Generic;
namespace YourNameSpace
{
public class YourConstructClass : Construct
{
public YourConstructClass(Construct scope, string id) : base(scope, id)
{
var thundraApiKey = <your_api_key>;
var handler = new Function(this, "YourHandler", new FunctionProps
{
..., // other function properties
Environment = new Dictionary<string, string>
{
..., // other environment variables
["thundra_apiKey"] = thundraApiKey
}
});
}
}
}
  • Change Handler of function to

    Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle

    and add thundra_agent_lambda_handler environment variable with the actual handler of your function.

using Amazon.CDK;
using Amazon.CDK.AWS.Lambda;
using System.Collections.Generic;
namespace YourNameSpace
{
public class YourConstructClass : Construct
{
public YourConstructClass(Construct scope, string id) : base(scope, id)
{
var thundraApiKey = <your_api_key>;
var handler = new Function(this, "YourHandler", new FunctionProps
{
..., // other function properties
Handler = "Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle",
Environment = new Dictionary<string, string>
{
..., // other environment variables
["thundra_apiKey"] = thundraApiKey,
["thundra_agent_lambda_handler"] = "Your.Assembly::Your.Type::YourMethod"
}
});
}
}
}

An example configuration:

using Amazon.CDK;
using Amazon.CDK.AWS.Lambda;
using System.Collections.Generic;
namespace YourNameSpace
{
public class YourConstructClass : Construct
{
public YourConstructClass(Construct scope, string id) : base(scope, id)
{
var thundraApiKey = <your_api_key>;
var handler = new Function(this, "WidgetHandler", new FunctionProps
{
Runtime = Runtime.DOTNET_CORE_3_1,
Code = Code.FromAsset("path/to/function/package"),
Handler = "Thundra.Agent.Lambda::Thundra.Agent.Lambda.Core.ThundraProxy::Handle",
Environment = new Dictionary<string, string>
{
["thundra_apiKey"] = thundraApiKey,
["thundra_agent_lambda_handler"] = "Your.Assembly::Your.Type::YourMethod"
}
});
}
}
}

Step 2: Build / Deploy

dotnet build src && cdk deploy

Step 3: Invoke your function!

Now you can try to invoke your Lambda function and see the details of your invocation in the Thundra console!

Programmatic Configuration

Step 1: Add Thundra NuGet package

The .NET Thundra agent can simply be downloaded with the command below:

dotnet add package Thundra.Agent.Lambda --version $LATEST_VERSION
Latest version

Similarly, including agent can be done via the NuGet Package Manager of your IDE if it is available. For example, Visual Studio allows you to add packages through the IDE itself, and a simple search of Thundra .NET will allow you to procure the correct agent to be added to your project.

Step 2: Change Handler's code

You should extend Thundra's LambdaRequestHandler within your handler class and override the DoHandleRequest method which encapsulates your handler code. LambdaRequestHandler takes two Generic classes as parameters: the request object's type and the response object's type.

Function.cs
using Amazon.Lambda.Core;
using Thundra.Agent.Lambda.Core;
namespace ThundraSample
{
public class Function : LambdaRequestHandler<string, string>
{
/// <summary>
/// Handler class needs to extend `LambdaRequestHandler< Request, Response >`
/// Please write all code within the DoHandleRequest method
/// </summary>
/// <param name="request"></param>
/// <param name="context"></param>
/// <returns>/Greeting Message/</returns>
public override string DoHandleRequest(string request, ILambdaContext context)
{
return "Hello Thundra";
}
}
}

Step 3: Change Your Handler to Thundra's HandleRequest

Next, you should change your handler to <MyAssembly>::<MyNamespace>.<MyClass>::HandleRequest.

It is a common mistake to point the hook method DoHandleRequest as the handler. In order to Thundra initialize you must change your handler to HandleRequest which resides in the base class(LambdaRequestHandler).