Lambda Extensions

With AWS Lambda Extensions, Lumigo can profile your Lambda invocations and collect additional metrics and information on specific executions. This currently includes:

  • CPU Load - the amount of computational work that the system performed when running your code.
  • CPU Over Time
  • Memory Over Time
  • Network Usage - the amount of network traffic your Lambda function used during the invocation.
1424

How to add the Lumigo Lambda Extension?

  1. Make sure your functions are traced using Auto-Tracing or Manual Tracing.
  2. Add this Lambda Layer to your Lambda functions' configuration:
    arn:aws:lambda:<region>:114300393969:layer:lumigo-extension:3
  3. (Only if you are using manual tracing) Add your Lumigo token as an environment variable with the key LUMIGO_TRACER_TOKEN. You can find your token in your Lumigo project's settings.
    Onboarding page.
KeyValue
LUMIGO_TRACER_TOKEN<YOUR_LUMIGO_TOKEN>

NOTE: the additional attributes (CPU Load, Network Usage etc.) for an invocation will only be available after a consequent invocation has been executed (or after ~10 minutes in case there are no consequent invocations).
In addition, the extension will not monitor short (<1.5s) lambdas.

How to add the extension when using Docker image?

  1. At the top of your Dockerfile, add:
FROM alpine:latest as lumigo-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}
RUN apk add aws-cli curl unzip
RUN mkdir -p /opt
RUN curl $(aws lambda get-layer-version-by-arn --arn arn:aws:lambda:${AWS_DEFAULT_REGION}:114300393969:layer:lumigo-extension:3 --query 'Content.Location' --output text) --output layer.zip
RUN unzip layer.zip -d /opt
RUN rm layer.zip
FROM scratch
  1. In the original Dockerfile code, after the "FROM" line, add:
COPY --from=lumigo-layer-copy /opt /opt

A complete example:

# Add the following lines at the beginning of the Dockerfile
FROM alpine:latest as lumigo-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}
RUN apk add aws-cli curl unzip
RUN mkdir -p /opt
RUN curl $(aws lambda get-layer-version-by-arn --arn arn:aws:lambda:${AWS_DEFAULT_REGION}:114300393969:layer:lumigo-extension:3 --query 'Content.Location' --output text) --output layer.zip
RUN unzip layer.zip -d /opt
RUN rm layer.zip
FROM scratch

# This is an example, you can replace the following lines with your original Dockerfile code
FROM public.ecr.aws/lambda/python:3.7
# The following line should be added to your original Dockerfile code
COPY --from=lumigo-layer-copy /opt /opt

COPY my_lambda.py /var/task/
RUN python3.7 -m pip install lumigo_tracer --target /var/task/
CMD [ "my_lambda.handler" ]
  1. When running docker build, add to following arguments to the command:
--build-arg AWS_ACCESS_KEY_ID=<your-access-key-id> --build-arg AWS_SECRET_ACCESS_KEY=<your-secret-access-key> --build-arg AWS_DEFAULT_REGION=<your-region>

For more information you can check: https://aws.amazon.com/blogs/compute/working-with-lambda-layers-and-extensions-in-container-images/ (Copy the contents of a Lambda layer into a container image)