AWS Lambda

Tracing Lambda functions can be done in three methods:

  1. Inherit from Epsagon's LambdaHandler Base Class.
  2. Passing a callback.
  • Set the following environment variables:
    • EPSAGON_TOKEN - Epsagon's token, can be found in the Dashboard.
    • EPSAGON_APP_NAME - Name for the application of this function (optional).
  • Generate a new AWS Lambda Function project (For more info).
  • Add Epsagon.Dotnet.Lambda package to your project.

To Inherit from Epsagon's LambdaHandler Base Class (example for S3 trigger)

public class Function : LambdaHandler<S3Event, string> // LambdaHandler<TEvent, TRes>
{
    public override string HandlerFunction(S3Event input, ILambdaContext context)
    {
        return "Hello from Epsagon!";
    }
}

Change the function-handler in your project's aws-lambda-tools-defaults.json to be EpsagonEnabledHandler.

Passing a callback

  • Add a call to EpsagonBootstrap.Bootstrap() in the constructor of your Lambda.
  • Invoke EpsagonHandler.Handle to instrument your function.
public class FunctionClass {
    public FunctionClass() {
        EpsagonBootstrap.Bootstrap();
    }

    public string MyHandler(S3Event input, ILambdaContext context) {
        return EpsagonHandler.Handle(input, context, () => {
            // your code is here...
        });
    }

    // Can be async as well
    public Task<string> MyAsyncHandler(S3Event input, ILambdaContext context) {
        return EpsagonHandler.Handle(input, context, async () => {
            // your async code is here
        });
    }
}

Did this page help you?