Skip to main content

AWS Lambda Layer

Using Epsagon's Layers in Lambda#

Our layers are publicly available for Python and Node.js Lambda runtimes. With just a few Environment Variables, the layer will automatically add tracing to your functions.

cURL https://layers.epsagon.com/production with query parameters:

  • region=REGION
  • name=epsagon-LANGUAGE-layer
  • max_items=1

to fetch the latest layer ARN. Choices for REGION include all AWS regions. Choices for LANGUAGE include python and node.

For example, to get the latest layer for Node.js in us-east-1: The endpoint would become https://layers.epsagon.com/production?region=us-east-1&name=epsagon-node-layer&max_items=1

fetch(  "https://layers.epsagon.com/production?region=us-east-1&name=epsagon-node-layer&max_items=1")  .then((r) => r.json())  .then((r) => r.LayerVersions[0].LayerVersionArn);

The ARN has a format of arn:aws:lambda:REGION:066549572091:layer:epsagon-LANGUAGE-layer:VERSION Add this layer to your function, and finalize tracing with environment variables.

For Zip Archives#

Add the layer with its ARN to the lambda function, and the function is good to go!

For Container Images#

A bit of processing is needed to add the layer to the container. Start by obtaining the ARN for the layer.

FROM alpine:latest as layer-copy
ARG AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-"us-east-1"}ARG AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-""}ARG AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-""}ENV AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION}ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
ENV EPSAGON_TOKEN=<TOKEN># Auto-Tracing env vars

RUN apk add aws-cli curl unzip
RUN mkdir -p /opt
RUN curl $(aws lambda get-layer-version-by-arn --arn LAYER-ARN --query 'Content.Location' --output text) --output epsagon-layer.zipRUN unzip epsagon-layer.zip -d /optRUN rm epsagon-layer.zip

FROM scratchWORKDIR /optCOPY --from=layer-copy /opt .

And the layer has been added to your image container. From there, define your image as needed!

Environment Variables#

Configure Environment Vars for Node or Python auto-tracing. EPSAGON_TOKEN=TOKEN EPSAGON_APP_NAME=APP_NAME

(python only) AUTOWRAPT_BOOTSTRAP=epsagon

(node only) NODE_OPTIONS='-r epsagon-frameworks'