This page explains how to use the AppDynamics AWS Lambda Extension for Serverless APM (the AppDynamics Lambda extension), the recommended way to inject the Serverless Tracer at runtime. Use this option to dynamically add a layer to a Node.js or Python application.

This document is intended to provide information specifically for using the AppDynamics AWS Lambda Extension for Serverless APM in conjunction with AppDynamics. AWS Lambda is managed by AWS and is a separate product from AppDynamics solutions.

Before You Begin

After you have subscribed to Serverless APM for AWS Lambda and set up your environment variables, you can begin instrumentation. Ensure that your setup meets the following requirements:

  • Existing AWS Lambda functions built with Node.js version >=10.x or Python 3.6-3.8
  • Active Serverless APM for AWS Lambda subscription
  • AppDynamics SaaS Controller version >=4.5.11
  • Supported AWS Regions: eu-central-1, eu-north-1, eu-west-1, eu-west-2, eu-west-3, ap-northeast-1, ap-northeast-2, ap-south-1, ap-southeast-1, ap-southeast-2, ca-central-1, sa-east-1, us-east-1, us-east-2, us-west-1, us-west-2

Use AWS Lambda Layers to Inject the Serverless Tracer at Runtime

To install the Node.js or Python Serverless Tracer, configure your Lambda function to use the layer implementing the AppDynamics AWS Lambda Extension for Serverless APM.  The method for doing this differs, depending on whether your Lambda function is packaged as a zip archive or as a container image.

Add the AWS Lambda Extension to Your Function when packaged as a zip archive

To pull the AppDynamics layer from Amazon, add the Amazon Resource Number (ARN)  to your Lambda using either the AWS Management Console UI or the AWS CLI.

  1. Add the AWS Lambda Extension to Your Function
  2. Configure Environment Variables

Instrument a Lambda Function using the AWS UI

  1. In the AWS Management Console console, select Compute > Lambda.
  2. From the AWS Lambda panel, select a lambda that you want to instrument. 
  3. Select Layers.
  4. Click Add a layer.
  5. Under Choose a layer, select Specify an ARN. 
  6. Under Specify an ARN, enter the AWS Layer information:

    arn:aws:lambda:us-west-2:338050622354:layer:appdynamics-lambda-extension:15
    BASH

    The ARN region changes based on the AWS region where the lambda is deployed. For example, if your lambda is Europe (Frankfurt) eu-central-1, use:

    arn:aws:lambda:eu-central-1:338050622354:layer:appdynamics-lambda-extension:15
    BASH
  7. Click Add.

  8. To verify the layer is added to the lambda, click Layers. Under Layers, the appdynamics-lambda-extension displays.

  9. See Configure the Environment Variables.

Instrument a Lambda Function using AWS CLI

To pull the AppDynamics layer from Amazon, using the AWS CLI:

  1. See Configuring a function to use layers.
  2. See Configure the Environment Variables.

Configure Environment Variables

To finish injecting the tracer into AWS Lambda, configure environment variables depending on your programming language and version:

Node 10.x, Node 12.x, Node 14.x, and Python 3.8

Add the environment variable AWS_LAMBDA_EXEC_WRAPPER with the value: /opt/appdynamics-extension-script:

AWS_LAMBDA_EXEC_WRAPPER = /opt/appdynamics-extension-script
BASH

For Python 3.6 and Python 3.7

Add an environment variable APPDYNAMICS_PYTHON_AUTOINSTRUMENT with the value set to true:

APPDYNAMICS_PYTHON_AUTOINSTRUMENT = true
BASH

Add the AWS Lambda Extension to Your Function when packaged as a container image

When your Lambda functions are deployed as container images, Lambda layers cannot be added via the function configuration.  Instead, you must package the extension as part of your container image during the build process.  For more details refer to this AWS Blog article.

To add the AppDynamics Lambda extension to your Lambda container, you will need to use a Dockerfile like those provided below:

FROM amazon/aws-cli:2.2.4 AS downloader
 
ARG version_number=10
ARG access_key
ARG secret_key
ARG region
ARG cachebust
 
ENV AWS_ACCESS_KEY_ID=${access_key}
ENV AWS_SECRET_ACCESS_KEY=${secret_key}
ENV AWS_REGION=${region}
ENV VERSION_NUMBER=${version_number}
 
RUN yum install -y jq curl
RUN echo "Cache Bust: $cachebust"
RUN aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:716333212585:layer:appdynamics-lambda-extension:$VERSION_NUMBER | jq -r '.Content.Location' | xargs curl -o extension.zip
 
FROM public.ecr.aws/lambda/nodejs:14
 
COPY --from=downloader /aws/extension.zip .
RUN yum install -y unzip && unzip extension.zip -d /opt && rm -f extension.zip
 
COPY package.json ./
RUN npm install
COPY app.js ./
 
# You can overwrite command in `serverless.yml` template
CMD ["app.handler"]
FROM amazon/aws-cli:2.2.4 AS downloader

ARG version_number=10
ARG access_key
ARG secret_key
ARG region
ARG cachebust

ENV AWS_ACCESS_KEY_ID=${access_key}
ENV AWS_SECRET_ACCESS_KEY=${secret_key}
ENV AWS_REGION=${region}
ENV VERSION_NUMBER=${version_number}

RUN yum install -y jq curl
RUN echo "Cache Bust: $cachebust"
RUN aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:716333212585:layer:appdynamics-lambda-extension:$VERSION_NUMBER | jq -r '.Content.Location' | xargs curl -o extension.zip

FROM public.ecr.aws/lambda/nodejs:12

COPY --from=downloader /aws/extension.zip .
RUN yum install -y unzip && unzip extension.zip -d /opt && rm -f extension.zip

COPY package.json ./
RUN npm install
COPY app.js ./

# You can overwrite command in `serverless.yml` template
CMD ["app.handler"]


TEXT
FROM amazon/aws-cli:2.2.4 AS downloader

ARG version_number=10
ARG access_key
ARG secret_key
ARG region
ARG cachebust

ENV AWS_ACCESS_KEY_ID=${access_key}
ENV AWS_SECRET_ACCESS_KEY=${secret_key}
ENV AWS_REGION=${region}
ENV VERSION_NUMBER=${version_number}

RUN yum install -y jq curl
RUN echo "Cache Bust: $cachebust"
RUN aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:716333212585:layer:appdynamics-lambda-extension:$VERSION_NUMBER | jq -r '.Content.Location' | xargs curl -o extension.zip

FROM public.ecr.aws/lambda/nodejs:10

COPY --from=downloader /aws/extension.zip .
RUN yum install -y unzip && unzip extension.zip -d /opt && rm -f extension.zip

COPY package.json ./
RUN npm install
COPY app.js ./

# You can overwrite command in `serverless.yml` template
CMD ["app.handler"]
TEXT
FROM amazon/aws-cli:2.2.4 AS downloader

ARG version_number=10
ARG access_key
ARG secret_key
ARG region
ARG cachebust

ENV AWS_ACCESS_KEY_ID=${access_key}
ENV AWS_SECRET_ACCESS_KEY=${secret_key}
ENV AWS_REGION=${region}
ENV VERSION_NUMBER=${version_number}

RUN yum install -y jq curl
RUN echo "Cache Bust: $cachebust"
RUN aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:716333212585:layer:appdynamics-lambda-extension:$VERSION_NUMBER | jq -r '.Content.Location' | xargs curl -o extension.zip

FROM public.ecr.aws/lambda/python:3.8

 
COPY --from=downloader /aws/extension.zip .
RUN yum install -y unzip && unzip extension.zip -d /opt && rm -f extension.zip

COPY app.py ./

# You can overwrite command in `serverless.yml` template
CMD ["app.handler"]


TEXT
FROM amazon/aws-cli:2.2.4 AS downloader

ARG version_number=10
ARG access_key
ARG secret_key
ARG region
ARG cachebust

ENV AWS_ACCESS_KEY_ID=${access_key}
ENV AWS_SECRET_ACCESS_KEY=${secret_key}
ENV AWS_REGION=${region}
ENV VERSION_NUMBER=${version_number}

RUN yum install -y jq curl
RUN echo "Cache Bust: $cachebust"
RUN aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:716333212585:layer:appdynamics-lambda-extension:$VERSION_NUMBER | jq -r '.Content.Location' | xargs curl -o extension.zip

FROM public.ecr.aws/lambda/python:3.7

COPY --from=downloader /aws/extension.zip .
RUN yum install -y unzip && unzip extension.zip -d /opt && rm -f extension.zip

COPY app.py ./

# You can overwrite command in `serverless.yml` template
CMD ["app.handler"]


TEXT
FROM amazon/aws-cli:2.2.4 AS downloader

ARG version_number=10
ARG access_key
ARG secret_key
ARG region
ARG cachebust

ENV AWS_ACCESS_KEY_ID=${access_key}
ENV AWS_SECRET_ACCESS_KEY=${secret_key}
ENV AWS_REGION=${region}
ENV VERSION_NUMBER=${version_number}

RUN yum install -y jq curl
RUN echo "Cache Bust: $cachebust"
RUN aws lambda get-layer-version-by-arn --arn arn:aws:lambda:$AWS_REGION:716333212585:layer:appdynamics-lambda-extension:$VERSION_NUMBER | jq -r '.Content.Location' | xargs curl -o extension.zip

FROM public.ecr.aws/lambda/python:3.6

COPY --from=downloader /aws/extension.zip .
RUN yum install -y unzip && unzip extension.zip -d /opt && rm -f extension.zip

COPY app.py ./

# You can overwrite command in `serverless.yml` template
CMD ["app.handler"]


TEXT

To build the container image containing your code as well as the AppDynamics Lambda extension, make sure you have the correct Dockerfile in your current directory and use the docker build command; for example:

docker build --build-arg version_number=$version_number --build-arg access_key=$(aws configure get aws_access_key_id) --build-arg secret_key=$(aws configure get aws_secret_access_key) --build-arg region=$(aws configure get region) -t <your tag> --build-arg cachebust=$(date +%s) .
BASH

Verify your Serverless Tracer Instrumentation

See Verify the Serverless Tracer Instrumentation.

Amazon Web Services, the AWS logo, AWS, and any other AWS Marks used in these materials are trademarks of Amazon.com, Inc. or its affiliates in the United States and/or other countries.