AWS Lambda

Tracing Lambda functions can be done in 3 simple steps:

Import AWS and Epsagon libraries

import (
  "log"
  "github.com/aws/aws-lambda-go/events"
  "github.com/aws/aws-lambda-go/lambda"
  "github.com/epsagon/epsagon-go/epsagon"
)

Create a Handler for your Lambda function

func handler (request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
  log.Println("In handler, recieved body: ", request.Body)
  return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}

Wrap your Handler with Epsagon

func main () {
  config := epsagon.NewTracerConfig(<APP-NAME-STAGE>, <EPSAGON-TOKEN>)
  lambda.Start(epsagon.WrapLambdaHandler(config, handler))
}

Your Lambda function should now be traced by Epsagon.

Example

A sample script might look like:

package main

import (
  "log"
  "github.com/aws/aws-lambda-go/events"
  "github.com/aws/aws-lambda-go/lambda"
  "github.com/epsagon/epsagon-go/epsagon"
)

func handler (request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
  log.Println("In handler, recieved body: ", request.Body)
  return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
}

func main () {
  config := epsagon.NewTracerConfig(<APP-NAME-STAGE>, <EPSAGON-TOKEN>)
  lambda.Start(epsagon.WrapLambdaHandler(config, handler))
}

Did this page help you?