• /
  • EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

この機械翻訳は、参考として提供されています。

英語版と翻訳版に矛盾がある場合は、英語版が優先されます。詳細については、このページを参照してください。

問題を作成する

コンテナ化されたインストゥルメンテーション

Lambda関数のコンテナ化されたイメージを使用していて、アプリケーションを監視したい場合は、関数のランタイムに一致する、事前に構築されたNew Relic LambdaレイヤーをDockerfileに追加する必要があります。

以下は、関数をモニターできるようにNew Relicを Dockerfile に追加するプロセスを示す図です。

A diagram demonstrating how New Relic integrates with your Lambda containerized function.

Lambda関数にコンテナ化されたイメージを使用している場合は、イメージにNew Relicを追加できます。

事前に構築されたレイヤーをコードに追加するためのガイドを以下に示します。

DockerfileにNew Relicを追加する

New Relicは、レイヤーのさまざまなランタイム(Java、Node.js、 Python、拡張機能のみ。

  1. 特定の Lambda 関数のランタイムとリージョンと互換性のあるレイヤーを選択します。

  2. マルチステージ Dockerfile では、New Relic のビルド済みイメージを中間ビルドステージとして使用します。 次に、New Relic のエージェントと拡張機能を、事前に構築されたイメージから最終ビルド ステージにコピーします。

    ランタイムに基づくDockerfileの例

    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-java:21 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/java:21
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to one of New Relic's handler wrappers
    CMD [ "com.newrelic.java.HandlerWrapper::handleRequest" ]
    # CMD [ "com.newrelic.java.HandlerWrapper::handleStreamsRequest" ]
    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-python:311 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/python:3.11
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to New Relic's handler wrapper
    CMD [ "newrelic_lambda_wrapper.handler" ]
    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-nodejs:20 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/nodejs:20
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to New Relic's handler wrapper
    CMD [ "newrelic-lambda-wrapper.handler" ]
    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-ruby:33 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/ruby:3.3
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to New Relic's handler wrapper
    CMD [ "newrelic_lambda_wrapper.handler" ]
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-dotnet:x86_64 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/dotnet:8
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override not needed since the dotnet layer does not have a handler wrapper
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-lambdaextension:x86 as layer
    # Any lambda base image can be used
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override not needed since the extension layer does not have an agent

画像を作成する

  1. New Relic のビルド済みイメージへの参照を Dockerfile に追加したら、変更された Dockerfile から新しいイメージをビルドする必要があります。 この新しいイメージには、元のコードと New Relic の事前構築されたイメージが含まれます。 これを行うには、 AWSガイドの「コンテナ イメージを使用して Lambda 関数を作成する」に記載されている手順に従うことをお勧めします。
  2. 関数が使用できるように、新しいイメージをAWS Elastic Container Registryリポジトリにプッシュします。

新しいLambda関数を作成する

AWS ECR にプッシュしたイメージを使用して、新しい Lambda 関数を作成します。 この関数の作成に関する詳細については、 AWSガイド「Lambda 関数の作成」を参照することをお勧めします。

Lambda関数を設定する

  1. Lambda 関数を元の関数と同じ設定で構成しますが、 New Relic Lambda 監視 に必要な環境変数を必ず追加してください。 詳細については、 環境変数を参照してください。

  2. 関数のハンドラーを更新して、関数のcmdオーバーライドで新しくアタッチされたレイヤーを指すようにします。 次の 2 つのドキュメントの指示に従ってそれを実行できます。

Copyright © 2024 New Relic株式会社。

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.