AppDynamics AWS Lambda Extension を使用して、実行時にサーバレス APM をインストゥルメントする
このページでは、実行時にサーバーレストレーサを挿入するための推奨方法である Splunk AppDynamics AWS Lambda Extension for Serverless APM(Splunk AppDynamicsLambda 拡張機能)の使用方法について説明します。このオプションを使用して、Node.js または Python アプリケーションにレイヤを動的に追加します。
- AWS Lambda に関連する質問については、AWS Lambda のマニュアルを参照してください。
- Splunk AppDynamics AWS Lambda Extension for Serverless APM に関連する質問については、「AWS Lambda 向けサーバーレス APM」を参照してください。
はじめる前に
Subscribe to Serverless APM for AWS LambdaAWS Lambda 向けサーバーレス APM に登録し、環境変数を設定すると、インストルメンテーションを開始できます。セットアップが次の要件を満たしていることを確認します。
-
既存の AWS Lambda 関数が Node.js バージョン 16.x、18.x、20.x または Python 3.7 ~ 3.9 で作成されている
- AWS Lambda 向けアクティブサーバレス APM のサブスクリプション
- Splunk AppDynamics SaaS コントローラバージョン 4.5.11 以上
- サポートされる AWS リージョン: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
AWS Lambda レイヤを使用して実行時にサーバレストレーサを挿入する
Node.js または Python サーバーレストレーサをインストールするには、Splunk AppDynamics AWS Lambda Extension for Serverless APM を実装するレイヤを使用するように Lambda 関数を構成します。これを実行する方法は、Lambda 関数が zip アーカイブとしてパッケージ化されているか、コンテナイメージとしてパッケージ化されているかによって異なります。
Add the AWS Lambda Extension to Your Function when packaged as a zip archive
Instrument a Lambda Function using the AWS UI
Instrument a Lambda Function using AWS CLI
To pull the Splunk AppDynamics layer from Amazon1, using the AWS CLI:
Configure Environment Variables
To finish injecting the tracer into AWS Lambda, configure environment variables depending on your programming language and version:
Node 16.x, Node 18.x, Node 20.x, and Python 3.9 to 3.13
Add the environment variable AWS_LAMBDA_EXEC_WRAPPER with the value: /opt/appdynamics-extension-script:
AWS_LAMBDA_EXEC_WRAPPER = /opt/appdynamics-extension-script
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 Cisco AppDynamics Lambda extension to your Lambda container, you will need to use a Dockerfile like those provided below:
- Node.js 20
-
JSON
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:20 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"] - Node.js 18
-
JSON
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:18 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"] - Node.js 16
-
JSON
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:16 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"] - Python 3.9
-
JSON
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.9 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"] - Python 3.10
-
JSON
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.10 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"] - Python 3.11
-
JSON
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.11 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"] - Python 3.12
-
JSON
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.12 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"] - Python 3.13
-
JSON
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.13 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"]
To build the container image containing your code as well as the Cisco 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) .