Skip to content
99 changes: 99 additions & 0 deletions docs/lambda/configure-lambda-widget.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
++++
<div class="tabs" data-tab-group="os">
<div role="tablist" aria-label="dependency">
<button role="tab"
aria-selected="true"
aria-controls="console-tab-lambda-java-config"
id="console-lambda-java-config">
AWS Web Console
</button>
<button role="tab"
aria-selected="false"
aria-controls="cli-tab-lambda-java-config"
id="cli-lambda-java-config"
tabindex="-1">
AWS CLI
</button>
<button role="tab"
aria-selected="false"
aria-controls="sam-tab-lambda-java-config"
id="sam-lambda-java-config"
tabindex="-1">
SAM
</button>
<button role="tab"
aria-selected="false"
aria-controls="serverless-tab-lambda-java-config"
id="serverless-lambda-java-config"
tabindex="-1">
Serverless
</button>
<button role="tab"
aria-selected="false"
aria-controls="terraform-tab-lambda-java-config"
id="terraform-lambda-java-config"
tabindex="-1">
Terraform
</button>
</div>
<div tabindex="0"
role="tabpanel"
id="console-tab-lambda-java-config"
name="lambda-tabpanel"
aria-labelledby="console-lambda-java-config">
++++

include::configure-lambda.asciidoc[tag=console-{layer-section-type}]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="cli-tab-lambda-java-config"
name="lambda-tabpanel"
aria-labelledby="cli-lambda-java-config"
hidden="">
++++

include::configure-lambda.asciidoc[tag=cli-{layer-section-type}]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="sam-tab-lambda-java-config"
name="lambda-tabpanel"
aria-labelledby="sam-lambda-java-config"
hidden="">
++++

include::configure-lambda.asciidoc[tag=sam-{layer-section-type}]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="serverless-tab-lambda-java-config"
name="lambda-tabpanel"
aria-labelledby="serverless-lambda-java-config"
hidden="">
++++

include::configure-lambda.asciidoc[tag=serverless-{layer-section-type}]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="terraform-tab-lambda-java-config"
name="lambda-tabpanel"
aria-labelledby="terraform-lambda-java-config"
hidden="">
++++

include::configure-lambda.asciidoc[tag=terraform-{layer-section-type}]

++++
</div>
</div>
++++
95 changes: 95 additions & 0 deletions docs/lambda/configure-lambda.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// tag::console-with-agent[]

To configure APM through the AWS Management Console:

1. Navigate to your function in the AWS Management Console
2. Click on the _Configuration_ tab
3. Click on _Environment variables_
4. Add the following required variables:

[source,bash]
----
AWS_LAMBDA_EXEC_WRAPPER = /opt/elastic-apm-handler # use this exact fixed value
ELASTIC_APM_LAMBDA_APM_SERVER = <YOUR-APM-SERVER-URL> # this is your APM Server URL
ELASTIC_APM_SECRET_TOKEN = <YOUR-APM-SECRET-TOKEN> # this is your APM secret token
----

--
include::{apm-aws-lambda-root}/docs/images/images.asciidoc[tag=java-env-vars]
--

// end::console-with-agent[]

// tag::cli-with-agent[]

To configure APM through the AWS command line interface execute the following command:

[source,bash]
----
aws lambda update-function-configuration --function-name yourLambdaFunctionName \
--environment "Variables={AWS_LAMBDA_EXEC_WRAPPER=/opt/elastic-apm-handler,ELASTIC_APM_LAMBDA_APM_SERVER=<YOUR-APM-SERVER-URL>,ELASTIC_APM_SECRET_TOKEN=<YOUR-APM-SECRET-TOKEN>}"
----

// end::cli-with-agent[]

// tag::sam-with-agent[]

In your SAM `template.yml` file add the Layer ARNs of the APM Extension and the APM Agent as follows:

[source,yml]
----
...
Resources:
yourLambdaFunction:
Type: AWS::Serverless::Function
Properties:
...
Environment:
Variables:
AWS_LAMBDA_EXEC_WRAPPER: /opt/elastic-apm-handler
ELASTIC_APM_LAMBDA_APM_SERVER: <YOUR-APM-SERVER-URL>
ELASTIC_APM_SECRET_TOKEN: <YOUR-APM-SECRET-TOKEN>
...
----

// end::sam-with-agent[]

// tag::serverless-with-agent[]

In your `serverless.yml` file add the Layer ARNs of the APM Extension and the APM Agent to your function as follows:

[source,yml]
----
...
functions:
yourLambdaFunction:
...
environment:
AWS_LAMBDA_EXEC_WRAPPER: /opt/elastic-apm-handler
ELASTIC_APM_LAMBDA_APM_SERVER: <YOUR-APM-SERVER-URL>
ELASTIC_APM_SECRET_TOKEN: <YOUR-APM-SECRET-TOKEN>
...
----

// end::serverless-with-agent[]

// tag::terraform-with-agent[]
To add the APM Extension and the APM Agent to your function add the ARNs to the `layers` property in your Terraform file:

[source,terraform]
----
...
resource "aws_lambda_function" "your_lambda_function" {
...
environment {
variables = {
AWS_LAMBDA_EXEC_WRAPPER = "/opt/elastic-apm-handler"
ELASTIC_APM_LAMBDA_APM_SERVER = "<YOUR-APM-SERVER-URL>"
ELASTIC_APM_SECRET_TOKEN = "<YOUR-APM-SECRET-TOKEN>"
}
}
}
...
----

// end::terraform-with-agent[]
7 changes: 7 additions & 0 deletions docs/lambda/java-arn-replacement.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
++++
<script>
window.addEventListener("DOMContentLoaded", async () => {
addArnGenerator('agent', 'apm-agent-java', 'arn:aws:lambda:${region}:267093732750:layer:elastic-apm-java-${version}');
});
</script>
++++
93 changes: 38 additions & 55 deletions docs/setup-aws-lambda.asciidoc
Original file line number Diff line number Diff line change
@@ -1,81 +1,64 @@
[[aws-lambda]]
=== Get started with Lambda
=== Monitoring AWS Lambda Java Functions
:layer-section-type: with-agent

Getting Elastic APM set up for your lambda functions is easy,
and there are various ways you can tweak it to fit your needs.

NOTE: In order to get the full AWS Lambda tracing capabilities, use with APM Server 7.16 or higher. Using
older versions provides most value, but some relevant metadata fields will not be indexed.
The Java APM Agent can be used with AWS Lambda to monitor the execution of your AWS Lambda functions.

[float]
[[aws-lambda-runtimes]]
==== Supported runtimes

AWS Lambda provides multiple https://docs.aws.amazon.com/lambda/latest/dg/java-image.html[JVM base images], only the ones that support the `AWS_LAMBDA_EXEC_WRAPPER` environment variables
are supported out of the box.

Running with unsupported images is still possible but requires providing agent configuration through environment variables
explicitly.
[[aws-lambda-java-quick-start]]
=== Quick Start

|===
|Tags |Java Runtime |Operating System|Supported
To get started with APM for your Java AWS Lambda functions, follow the steps below.

|11
|Java 11 (Corretto)
|Amazon Linux 2
|yes
[float]
[[aws-lambda-java-prerequisites]]
==== Prerequisites

|8.al2
|Java 8 (Corretto)
|Amazon Linux 2
|yes
. You need an APM Server to send APM data to. Follow the {apm-guide-ref}/apm-quick-start.html[APM Quick start] if you have not set one up yet. For the best-possible performance, we recommend setting up APM on {ecloud} in the same AWS region as your AWS Lambda functions.
. Make sure you are using one of the supported AWS Lambda Java runtimes:
+
--
include::supported-technologies.asciidoc[tag=aws-lambda-runtimes]
--
Comment on lines +19 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I like this. FYI I moved the table include into a block element. This allows us to nest it under the accompanying bullet point with a +.


|8
|Java 8 (OpenJDK)
|Amazon Linux 2018.03
|no
[float]
==== Step 1: Select the AWS Region and Architecture

|===
include::{apm-aws-lambda-root}/docs/lambda-selector/lambda-attributes-selector.asciidoc[]

[float]
[[aws-lambda-installation]]
==== Installation
==== Step 2: Add the APM Layers to your Lambda function

Setting up APM for your Java Lambda function is a two-step process. Make sure to follow _both_ of the following steps:
include::{apm-aws-lambda-root}/docs/lambda-selector/extension-arn-replacement.asciidoc[]
include::./lambda/java-arn-replacement.asciidoc[]

1. <<aws-lambda-extension>>
2. <<aws-lambda-instrumenting>>
Both the {apm-guide-ref}/aws-lambda-arch.html[APM Lambda Extension] and the Java APM Agent are added to your Lambda function as https://docs.aws.amazon.com/lambda/latest/dg/invocation-layers.html[AWS Lambda Layers]. Therefore, you need to add the corresponding Layer ARNs (identifiers) to your Lambda function.

include::{apm-aws-lambda-root}/docs/add-extension/add-extension-layer-widget.asciidoc[]

[float]
[[aws-lambda-extension]]
==== Install the Elastic APM Lambda extension
==== Step 3: Configure APM on AWS Lambda

Elastic uses a Lambda extension to forward data to an APM Server in a way that does not interfere with the execution of your Lambda function.
The APM Lambda Extension and the APM Java agent are configured through environment variables on the AWS Lambda function.

Follow the https://www.elastic.co/guide/en/apm/guide/current/aws-lambda-extension.html[installation documentation for the extension] to setup the Elastic APM Lambda extension for your Lambda function.
For the minimal configuration, you will need the _APM Server URL_ to set the destination for APM data and an _{apm-guide-ref}/secret-token.html[APM Secret Token]_.
If you prefer to use an {apm-guide-ref}/api-key.html[APM API key] instead of the APM secret token, use the `ELASTIC_APM_API_KEY` environment variable instead of `ELASTIC_APM_SECRET_TOKEN` in the following configuration.

[float]
[[aws-lambda-instrumenting]]
==== Install the Elastic APM Java Agent Layer
include::./lambda/configure-lambda-widget.asciidoc[]

The Java Agent is installed as an AWS Layer.
You can optionally <<configuration, fine-tune the Java agent >> or the {apm-guide-ref}/aws-lambda-config-options.html[configuration of the APM Lambda Extension].

1. Pick the right ARN from the https://github.com/elastic/apm-agent-java/releases[ARN table for the APM Java Agent Lambda Layer]. Note: The APM Java Agent Layer needs to be in the _same region_ as your Lambda function.
2. Navigate to your function in the AWS Console
3. Scroll to the Layers section and click the _Add a layer_ button
4. Choose the _Specify an ARN_ radio button
5. Enter the Version ARN of the APM Java Agent Layer in the _Specify an ARN_ text input
6. Click the _Add_ button
That's it; After following the steps above, you're ready to go!
Your Lambda function invocations should be traced from now on.

Once the APM Java Agent Layer is in place, you'll need to configure some environment variables _in addition_ to the environment variables you already configured for the APM Lambda extension.
Configure the following environment variables for the APM Java Agent Layer:
Read on to learn more about the features and limitations of the Java APM Agent on AWS Lambda Functions.

1. (required) `AWS_LAMBDA_EXEC_WRAPPER`: set this variable's value to `/opt/elastic-apm-handler`, so that Lambda starts the runtime with an attached APM Java agent.
2. (recommended) <<config-application-packages, `ELASTIC_APM_APPLICATION_PACKAGES`>>: setting this may improve cold start times.
3. (optional) Fine-tune the Java agent with any of the available <<configuration, configuration options>>.
[float]
[[aws-lambda-features-and-caveats]]
=== Features and Caveats

That's it, if you've done all of the above you are set to go!
Your Lambda function invocations should be traced from now on.
The AWS Lambda as a runtime behaves differently from conventional runtimes.
While most APM and monitoring concepts apply to AWS Lambda, there are a few differences and limitations to be aware of.

[float]
[[aws-lambda-performance-monitoring]]
Expand Down
34 changes: 34 additions & 0 deletions docs/supported-technologies.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This section lists all supported technologies.
* <<supported-logging-frameworks>>
* <<supported-process-frameworks>>
* <<supported-rpc-frameworks>>
* <<supported-aws-lambda-runtimes>>
* <<supported-java-methods>>
* <<supported-metrics>>
* <<supported-technologies-caveats>>
Expand Down Expand Up @@ -583,6 +584,39 @@ JBoss LogManager - 1.30.0

|===

[float]
[[supported-aws-lambda-runtimes]]
=== AWS Lambda runtimes

AWS Lambda provides multiple https://docs.aws.amazon.com/lambda/latest/dg/java-image.html[JVM base images]. Only those that support the `AWS_LAMBDA_EXEC_WRAPPER` environment variables are supported out of the box.

Running with unsupported images is still possible but requires providing agent configuration through environment variables
explicitly.

// tag::aws-lambda-runtimes[]

|===
|Tags |Java Runtime |Operating System|Supported

|11
|Java 11 (Corretto)
|Amazon Linux 2
|yes

|8.al2
|Java 8 (Corretto)
|Amazon Linux 2
|yes

|8
|Java 8 (OpenJDK)
|Amazon Linux 2018.03
|no

|===

// end::aws-lambda-runtimes[]

[float]
[[supported-java-methods]]
=== Java method monitoring
Expand Down