Skip to content

Commit cd71c26

Browse files
AlexanderWertestolfobmorelli25jlvoiseux
committed
Restructured docs for AWS Lambda (elastic#158)
* Restructured docs for AWS Lambda * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Emily S <[email protected]> * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Emily S <[email protected]> * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Emily S <[email protected]> * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Emily S <[email protected]> * add temp anchor to fix build * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Brandon Morelli <[email protected]> * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Brandon Morelli <[email protected]> * Update docs/monitoring-aws-lambda.asciidoc Co-authored-by: Brandon Morelli <[email protected]> * Update add-extension-layer.asciidoc * Fixed review comments * Adding missing config options * docs: add env imgs * add images * Added Node.js env-var image Co-authored-by: Emily S <[email protected]> Co-authored-by: bmorelli25 <[email protected]> Co-authored-by: Brandon Morelli <[email protected]> Co-authored-by: Jean-Louis Voiseux <[email protected]> # Conflicts: # docs/add-extension/add-extension-layer.asciidoc # docs/aws-lambda-extension.asciidoc # docs/lambda-selector/lambda-attributes-selector.asciidoc # docs/monitoring-aws-lambda.asciidoc
1 parent 3c1ea51 commit cd71c26

File tree

3 files changed

+59
-174
lines changed

3 files changed

+59
-174
lines changed

docs/add-extension/add-extension-layer.asciidoc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ To add a layer to a Lambda function through the AWS Management Console:
55
1. Navigate to your function in the AWS Management Console
66
2. Scroll to the Layers section and click the _Add a layer_ button image:images/config-layer.png[image of layer configuration section in AWS Console]
77
3. Choose the _Specify an ARN_ radio button
8-
4. Copy and paste the following ARN of the APM Lambda Extension layer in the _Specify an ARN_ text input: +
8+
4. Copy and paste the following ARN of the APM Lambda Extension layer in the _Specify an ARN_ text input: +
99
+++<span style="font-size:10pt"><b>EXTENSION_ARN</b></span>+++
1010
image:images/choose-a-layer.png[image of choosing a layer in AWS Console]
1111
5. Click the _Add_ button
@@ -19,7 +19,7 @@ To add the layers to your Lambda function through the AWS Management Console:
1919
1. Navigate to your function in the AWS Management Console
2020
2. Scroll to the Layers section and click the _Add a layer_ button image:images/config-layer.png[image of layer configuration section in AWS Console]
2121
3. Choose the _Specify an ARN_ radio button
22-
4. Copy and paste the following ARNs of the APM Lambda Extension layer and the APM agent layer in the _Specify an ARN_ text input: +
22+
4. Copy and paste the following ARNs of the APM Lambda Extension layer and the APM agent layer in the _Specify an ARN_ text input: +
2323
APM Extension layer: +
2424
+++<span style="font-size:10pt"><b>EXTENSION_ARN</b></span>+++ +
2525
APM Agent layer: +
@@ -61,12 +61,13 @@ In your SAM `template.yml` file add the APM Extension Layer ARN as follows:
6161
[source,yml]
6262
----
6363
...
64-
ServerlessFunction:
65-
Type: AWS::Serverless::Function
66-
Properties:
67-
...
68-
Layers:
69-
- EXTENSION_ARN
64+
Resources:
65+
yourLambdaFunction:
66+
Type: AWS::Serverless::Function
67+
Properties:
68+
...
69+
Layers:
70+
- EXTENSION_ARN
7071
...
7172
----
7273

@@ -79,13 +80,14 @@ In your SAM `template.yml` file add the Layer ARNs of the APM Extension and the
7980
[source,yml]
8081
----
8182
...
82-
ServerlessFunction:
83-
Type: AWS::Serverless::Function
84-
Properties:
85-
...
86-
Layers:
87-
- EXTENSION_ARN
88-
- AGENT_ARN
83+
Resources:
84+
yourLambdaFunction:
85+
Type: AWS::Serverless::Function
86+
Properties:
87+
...
88+
Layers:
89+
- EXTENSION_ARN
90+
- AGENT_ARN
8991
...
9092
----
9193

@@ -133,7 +135,6 @@ To add the APM Extension Layer to your function add the ARN to the `layers` prop
133135
----
134136
...
135137
resource "aws_lambda_function" "your_lambda_function" {
136-
function_name = "yourLambdaFunctionName"
137138
...
138139
layers = ["EXTENSION_ARN"]
139140
}
@@ -149,7 +150,6 @@ To add the APM Extension and the APM Agent to your function add the ARNs to the
149150
----
150151
...
151152
resource "aws_lambda_function" "your_lambda_function" {
152-
function_name = "yourLambdaFunctionName"
153153
...
154154
layers = ["EXTENSION_ARN", "AGENT_ARN"]
155155
}

docs/lambda-selector/lambda-attributes-selector.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ const addArnGenerator = async (type, ghRepo, arnPattern) => {
6868
const releases = await fetch(`https://api.github.com/repos/elastic/${ghRepo}/releases`).then(data => {
6969
return data.json();
7070
});
71-
71+
7272
releases.filter(release => !release.draft && release.body.includes('arn:aws:lambda:'));
73-
73+
7474
var latestRelease = releases[0];
7575
7676
releases.forEach(release => {
@@ -107,7 +107,7 @@ window.addEventListener("DOMContentLoaded", async () => {
107107
</script>
108108
109109
<div role="lambda-selector">
110-
<div role="lambda-selector-header">Select the AWS region and architecture of your Lambda function:</div>
110+
<div role="lambda-selector-header">Select the AWS region and architecture of your Lambda function. This documentation will update based on your selections.</div>
111111
<div role="lambda-selector-content">
112112
<div role="lambda-selector-input">
113113
<div>region:</div>
Lines changed: 39 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,194 +1,79 @@
1-
[[aws-lambda-extension]]
2-
= AWS Lambda Extension (Experimental)
3-
4-
experimental::[]
5-
6-
Elastic's APM Agents instrument AWS Lambda functions and dispatch APM data via an AWS Lambda Extension.
7-
8-
[discrete]
9-
[[aws-lambda-arch-old]]
10-
== Extension Architecture
11-
12-
Normally, during the execution of a Lambda function, there's only a single language process running in the AWS Lambda execution environment. However, with an AWS Lambda Extension, Lambda users can run a _second_ process alongside their main service/application process.
13-
14-
image:images/data-flow.png[image showing data flow from lambda function, to extension, to APM Server]
15-
16-
By using a custom-built AWS Lambda Extension, Elastic APM Agents can send data to a locally running Lambda Extension process, and that process will forward data on to APM Server. The Lambda Extension ensures that any latency between the Lambda function and the AWS Server instance will not cause latency in the Lambda function/Service itself.
17-
18-
[discrete]
19-
[[aws-lambda-instrumenting]]
20-
== Instrumenting a Lambda Function
21-
22-
The rest of this guide contains instructions for instrumenting a Lambda function. There are two high level steps to instrumenting an AWS Lambda function.
23-
24-
1. <<aws-lambda-configure-layer>>
25-
2. <<aws-lambda-handler>>
26-
27-
[discrete]
28-
[[aws-lambda-configure-layer]]
29-
=== Configuring the APM Lambda Extension Layer
30-
31-
First, you'll need to https://github.com/elastic/apm-aws-lambda/releases[pick the right ARN from the extension release table] for your AWS Lambda function. The ARN has the pattern `arn:aws:lambda:<AWS_REGION_KEY>:267093732750:layer:elastic-apm-extension-<APM_EXTENSION_VERSION>-<ARCHITECTURE_KEY>:<LAYER_VERSION>` and depends on:
32-
33-
* The AWS region your Lambda function runs in. The APM Lambda Extension layer needs to be in the same region as your Lambda function.
34-
* The architecture (_x86_64_ or _arm64_) used for your Lambda function.
35-
* The version of the APM Lambda Extension you would like to use.
1+
[[monitoring-aws-lambda]]
2+
= Monitoring AWS Lambda Functions
363

37-
You'll then need to configure your function to use that layer. To add a layer
4+
Elastic APM lets you monitor your AWS Lambda functions.
5+
The natural integration of {apm-guide-ref}/apm-distributed-tracing.html[distributed tracing] into your AWS Lambda functions provides insights into the functions' execution and runtime behavior as well as their relationships and dependencies to other services.
386

39-
1. Navigate to your function in the AWS Console
40-
2. Scroll to the Layers section and click the _Add a layer_ button image:images/config-layer.png[image of layer configuration section in AWS Console]
41-
3. Choose the _Specify an ARN_ radio button
42-
4. Enter the Version ARN of the APM Lambda Extension layer in the _Specify an ARN_ text input
43-
5. Click the _Add_ button
7+
To get started with the setup of Elastic APM for your Lambda functions, checkout the language-specific guides:
448

45-
[discrete]
46-
[[aws-lambda-env-vars]]
47-
==== Configure Environment Variables
9+
* {apm-node-ref}/lambda.html[Quick Start with APM on AWS Lambda - Node.js]
10+
* {apm-py-ref}/lambda-support.html[Quick Start with APM on AWS Lambda - Python]
11+
* {apm-java-ref}/aws-lambda.html[Quick Start with APM on AWS Lambda - Java]
4812

49-
Finally, once the layer's in place you'll need to configure a few environment variables. To configure variables
13+
Learn more about the <<aws-lambda-arch, architecture>> of Elastic APM for AWS Lambda.
5014

51-
1. Navigate to your function in the AWS Console
52-
2. Click on the _Configuration_ tab
53-
3. Click on _Environment variables_
54-
4. Add the necessary variables.
15+
[[aws-lambda-arch]]
16+
== APM Architecture for AWS Lambda
5517

56-
The following environment variables are relevant for instrumenting a Lambda function:
18+
AWS Lambda uses a special execution model to provide a scalable, on-demand compute service for code execution. In particular, AWS freezes the execution environment of a lambda function when no active requests are being processed. This execution model poses additional requirements on APM in the context of AWS Lambda functions:
5719

58-
* (required) `ELASTIC_APM_LAMBDA_APM_SERVER`: +
59-
This required config option controls where the Lambda extension will ship data. This should be the URL of the final APM Server destination for your telemetry.
60-
61-
* (required) `ELASTIC_APM_SECRET_TOKEN` or `ELASTIC_APM_API_KEY`: +
62-
One of these needs to be set as the authentication method that the extension uses when sending data to the URL configured via `ELASTIC_APM_LAMBDA_APM_SERVER`.
63-
64-
* (optional) `ELASTIC_APM_SERVICE_NAME`: +
65-
The configured name of your application or service. The APM Agent will use this value when reporting data to APM Server. If unset, the APM Agent will automatically set the value based on the Lambda function name. Use this config option if you want to group multiple Lambda functions under a single service entity in APM.
20+
1. To avoid data loss, APM data collected by APM agents needs to be flushed before the execution environment of a lambda function is frozen.
21+
2. Flushing APM data must be fast so as not to impact the response times of lambda function requests.
6622

67-
* (optional) `ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS`: +
68-
The timeout value, in seconds, for the Lambda Extension's server receiving data from the agent. The _default_ is `15`.
69-
70-
* (optional) `ELASTIC_APM_SEND_STRATEGY`: +
71-
Whether to synchronously flush APM agent data from the extension to the APM server at the end of the function invocation.
72-
The two accepted values are `background` and `syncflush`. The _default_ is `syncflush`.
73-
** The `background` strategy indicates that the extension will not flush when it receives a signal that the function invocation
74-
has completed. It will instead send any remaining buffered data on the next function invocation. The result is that, if the
75-
function is not subsequently invoked for that Lambda environment, the buffered data will be lost. However, for lambda functions
76-
that have a steadily frequent load pattern the extension could delay sending the data to the APM server to the next lambda
77-
request and do the sending in parallel to the processing of that next request. This potentially would improve both the lambda
78-
function response time and its throughput.
79-
** The other value, `syncflush` will synchronously flush all remaining buffered APM agent data to the APM server when the
80-
extension receives a signal that the function invocation has completed. This strategy blocks the lambda function from receiving
81-
the next request until the extension has flushed all the data. This has a negative effect on the throughput of the function,
82-
though it ensures that all APM data is sent to the APM server.
23+
To accomplish the above, Elastic's APM Agents instrument AWS Lambda functions and dispatch APM data via an https://docs.aws.amazon.com/lambda/latest/dg/using-extensions.html[AWS Lambda Extension].
8324

84-
An example configuration of the APM Lambda Extension might look like the following
25+
Normally, during the execution of a Lambda function, there's only a single language process running in the AWS Lambda execution environment. With an AWS Lambda Extension, Lambda users run a _second_ process alongside their main service/application process.
8526

86-
[source,bash]
87-
----
88-
ELASTIC_APM_LAMBDA_APM_SERVER=https://your-apm-server-url:443 # (required) this is your APM Server URL
89-
ELASTIC_APM_SECRET_TOKEN=shhhhhhitsasecret # (required) this is your APM Server's secret token
90-
ELASTIC_APM_SERVICE_NAME=yourApmServiceName # (optional) use this to group multiple lambda functions
91-
ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS=20 # (optional) wait 20s to receive data from the APM agent
92-
ELASTIC_APM_SEND_STRATEGY=background # (optional) this is the default strategy
93-
----
27+
image:images/architecture-white.png[image showing data flow from lambda function, to extension, to APM Server]
9428

95-
For a _minimal configuration_ you need to specify the `ELASTIC_APM_LAMBDA_APM_SERVER` and the `ELASTIC_APM_SECRET_TOKEN` config options.
96-
97-
[discrete]
98-
[[aws-lambda-handler]]
99-
=== Configuring the Agent and Lambda Function handler
100-
101-
After the extension has been installed, install the relevant language agent and wrap the Lambda function handler.
102-
103-
104-
[discrete]
105-
[[aws-lambda-nodejs]]
106-
==== Node.js
107-
108-
To install the Node.js agent in Lambda you'll use a second layer. You'll need to https://github.com/elastic/apm-agent-nodejs/releases[pick the right ARN from the agent release table]. The ARN has the pattern `arn:aws:lambda:<AWS_REGION_KEY>:267093732750:layer:elastic-apm-node-ver-<APM_EXTENSION_VERSION>:<LAYER_VERSION>` and depends on:
109-
110-
* The AWS region your Lambda function runs in. The APM Lambda Extension layer needs to be in the same region as your Lambda function.
111-
* The version of the APM Lambda Extension you would like to use.
112-
113-
You'll then need to configure your function to use that layer. To add a layer
114-
115-
1. Navigate to your function in the AWS Console
116-
2. Scroll to the Layers section and click the _Add a layer_ button image:images/config-layer.png[image of layer configuration section in AWS Console]
117-
3. Choose the _Specify an ARN_ radio button
118-
4. Enter the Version ARN of the APM Lambda Extension layer in the _Specify an ARN_ text input
119-
5. Click the _Add_ button
120-
121-
Finally, to have the Node.js agent automatically wrap your Lambda function handler, add the following environment variable.
122-
123-
[source]
124-
---
125-
NODE_OPTIONS=-r elastic-apm-node/start
126-
---
127-
128-
See the {apm-node-ref}/lambda.html[Node.js agent setup guide] for detailed instructions on setting up the Node.js agent for AWS Lambda.
129-
130-
[discrete]
131-
[[aws-lambda-python]]
132-
==== Python
133-
134-
In Python, you wrap a Lambda function handler using the following syntax.
135-
136-
[source,python]
137-
----
138-
from elasticapm import capture_serverless
139-
@capture_serverless()
140-
def handler(event, context):
141-
return {"statusCode": r.status_code, "body": "Success!"}
142-
----
143-
144-
See the {apm-py-ref}/lambda-support.html[Python agent setup guide] for detailed instructions on setting up the Python agent for AWS Lambda.
145-
146-
[discrete]
147-
[[aws-lambda-java]]
148-
==== Java
149-
150-
Like the extension, the Elastic APM Java agent is installed as a Lambda layer.
151-
152-
See the {apm-java-ref}/aws-lambda.html[Java agent setup guide] for detailed instructions on setting up the Java agent for AWS Lambda.
29+
By using an AWS Lambda Extension, Elastic APM Agents can send data to a local Lambda Extension process, and that process will forward data on to APM Server asynchronously. The Lambda Extension ensures that any potential latency between the Lambda function and the APM Server instance will not cause latency in the request flow of the Lambda function itself.
15330

15431
[[aws-lambda-config-options]]
15532
== Configuration Options for APM on AWS Lambda
15633

15734
The recommended way of configuring the APM Lambda Extension and the APM Agents on AWS Lambda is through the Lambda function's environment variables.
15835

159-
[float]
36+
The configuration options for the APM Agents are documented in the corresponding language agents:
37+
38+
* {apm-node-ref}/configuration.html[Configuration options - Node.js APM Agent]
39+
* {apm-py-ref}/configuration.html[Configuration options - Python APM Agent]
40+
* {apm-java-ref}/configuration.html[Configuration options - Java APM Agent]
41+
42+
The following configuration options are particularly relevant for Elastic's APM on AWS Lambda:
43+
44+
[[aws-lambda-extension]]
16045
=== `ELASTIC_APM_LAMBDA_APM_SERVER`
16146
This required config option controls where the Lambda extension will ship data. This should be the URL of the final APM Server destination for your telemetry.
16247

163-
[float]
16448
=== `ELASTIC_APM_SECRET_TOKEN` or `ELASTIC_APM_API_KEY`
16549
One of these needs to be set as the authentication method that the extension uses when sending data to the URL configured via `ELASTIC_APM_LAMBDA_APM_SERVER`.
16650

167-
[float]
16851
=== `ELASTIC_APM_SERVICE_NAME`
16952
The configured name of your application or service. The APM Agent will use this value when reporting data to the APM Server. If unset, the APM Agent will automatically set the value based on the Lambda function name. Use this config option if you want to group multiple Lambda functions under a single service entity in APM.
17053

171-
[float]
17254
=== `ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS`
173-
The timeout value, in seconds, for the Lambda Extension's server receiving data from the agent. The _default_ is `15`.
55+
The APM Lambda Extension's timeout value, in seconds, for receiving data from the APM Agent. The _default_ is `15`.
56+
57+
=== `ELASTIC_APM_DATA_RECEIVER_SERVER_PORT`
58+
The port on which the APM Lambda Extension listens to receive data from the APM Agent. The _default_ is `8200`.
59+
60+
=== `ELASTIC_APM_DATA_FORWARDER_TIMEOUT_SECONDS`
61+
The timeout value, in seconds, for the Lambda Extension's HTTP client sending data to the APM Server. The _default_ is `3`. If the Extension's attempt to send APM data during this time interval is not successful, the extension queues back the data. Further attempts at sending the data are governed by an exponential backoff algorithm: data will be sent after a increasingly large grace period of 0, then circa 1, 4, 9, 16, 25 and 36 seconds, provided that the Lambda function execution is ongoing.
17462

175-
[float]
17663
=== `ELASTIC_APM_SEND_STRATEGY`
177-
Whether to synchronously flush APM agent data from the extension to the APM server at the end of the function invocation.
64+
Whether to synchronously flush APM agent data from the extension to the APM Server at the end of the function invocation.
17865
The two accepted values are `background` and `syncflush`. The _default_ is `syncflush`.
17966

18067
* The `background` strategy indicates that the extension will not flush when it receives a signal that the function invocation
18168
has completed. It will instead send any remaining buffered data on the next function invocation. The result is that, if the
18269
function is not subsequently invoked for that Lambda environment, the buffered data will be lost. However, for lambda functions
183-
that have a steadily frequent load pattern the extension could delay sending the data to the APM server to the next lambda
70+
that have a steadily frequent load pattern the extension could delay sending the data to the APM Server to the next lambda
18471
request and do the sending in parallel to the processing of that next request. This potentially would improve both the lambda
18572
function response time and its throughput.
186-
* The other value, `syncflush` will synchronously flush all remaining buffered APM agent data to the APM server when the
73+
* The other value, `syncflush` will synchronously flush all remaining buffered APM agent data to the APM Server when the
18774
extension receives a signal that the function invocation has completed. This strategy blocks the lambda function from receiving
18875
the next request until the extension has flushed all the data. This has a negative effect on the throughput of the function,
18976
though it ensures that all APM data is sent to the APM server.
19077

191-
[role="exclude",id="aws-lambda-arch"]
192-
== AWS Lambda architecture
193-
194-
Please see <<aws-lambda-arch>> instead. This link will be fixed soon.
78+
=== `ELASTIC_APM_LOG_LEVEL`
79+
The logging level to be used by both the APM Agent and the Lambda Extension. Supported values are `trace`, `debug`, `info`, `warning`, `error`, `fatal` and `panic`.

0 commit comments

Comments
 (0)