You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/aws-lambda-extension.asciidoc
+54-3Lines changed: 54 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,11 @@
1
1
[[aws-lambda-extension]]
2
2
= AWS Lambda Extension (Experimental)
3
3
4
+
experimental::[]
5
+
4
6
Elastic's APM Agents instrument AWS Lambda functions via an AWS Lambda Extension.
5
7
8
+
[discrete]
6
9
[[aws-lambda-arch]]
7
10
== Extension Architecture
8
11
@@ -12,6 +15,8 @@ image:images/data-flow.png[image showing data flow from lambda function, to exte
12
15
13
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.
14
17
18
+
[discrete]
19
+
[[aws-lambda-instrumenting]]
15
20
== Instrumenting a Lambda Function
16
21
17
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.
@@ -21,6 +26,7 @@ The rest of this guide contains instructions for instrumenting a Lambda function
21
26
22
27
We'll start with installing the Lambda extension.
23
28
29
+
[discrete]
24
30
[[aws-lambda-install]]
25
31
== Installing the Lambda Extension
26
32
@@ -63,6 +69,8 @@ The `elastic-lambda.js` command assumes you have a `install.yaml` file configure
63
69
./elastic-lambda.js install
64
70
----
65
71
72
+
[discrete]
73
+
[[aws-lambda-configuring]]
66
74
== Configuring the Installer
67
75
68
76
A fully configured `install.yaml` might look like the following
@@ -83,47 +91,68 @@ install:
83
91
84
92
The meaning of each `install.yaml` configuration field is as follows.
85
93
94
+
[discrete]
95
+
[[aws-lambda-layer_name]]
86
96
=== `layer_name`
87
97
88
98
This is the name the compiler will use for your AWS Layer. The default, `apm-lambda-extension`, should work for most scenarios.
89
99
100
+
[discrete]
101
+
[[aws-lambda-function_name]]
90
102
=== `function_name`
91
103
92
104
The name of your Lambda function. The installer will use this to configure the correct Lambda function. This must be the name of a function that already exists.
93
105
106
+
[discrete]
107
+
[[aws-lambda-lambda_env]]
94
108
=== `lambda_env`
95
109
96
110
The installer will use the key/value pairs in this section of the configuration file to add environment variables to your Lambda function. The provided variables are those required to make the extension work correctly.
97
111
112
+
[discrete]
113
+
[[aws-lambda-log_level]]
98
114
==== `ELASTIC_APM_LOG_LEVEL`
99
115
100
116
The log level for the APM Agent. Consult your https://www.elastic.co/guide/en/apm/agent/index.html[APM Agent's documentation] for more information.
101
117
118
+
[discrete]
119
+
[[aws-lambda-secret_token]]
102
120
==== `ELASTIC_APM_SECRET_TOKEN`
103
121
104
122
The APM secret token. The extension will use this when communicating with APM Server.
105
123
124
+
[discrete]
125
+
[[aws-lambda-api_key]]
106
126
==== `ELASTIC_APM_API_KEY`
107
127
108
128
An alternative authentication method to the secret token. The extension will use this when communicating with APM Server.
109
129
130
+
[discrete]
131
+
[[aws-lambda-server_url]]
110
132
==== `ELASTIC_APM_SERVER_URL`
111
133
112
134
Your APM Server URL. This is the final destination for your data.
113
135
136
+
[discrete]
137
+
[[aws-lambda-service_name]]
114
138
==== `ELASTIC_APM_SERVICE_NAME`
115
139
116
140
The configured name of your application or service. The APM Agent will use this value when reporting data to APM Server.
117
141
If unset, the APM Agent will automatically set the value based on `AWS_LAMBDA_FUNCTION_NAME` or `context.functionName`.
118
142
143
+
[discrete]
144
+
[[aws-lambda-timeout_seconds]]
119
145
==== `ELASTIC_APM_DATA_RECEIVER_TIMEOUT_SECONDS`
120
146
121
147
The timeout value, in seconds, for the Lambda Extension's server.
122
148
149
+
[discrete]
150
+
[[aws-lambda-handler]]
123
151
== Configuring the Agent and Lambda Function handler
124
152
125
153
Once you've installed the extension, there's one last step to take. You'll need to wrap the Lambda function handler.
It's possible to install and configure the extension manually. In order to do so, you'll need to
@@ -163,22 +195,28 @@ It's possible to install and configure the extension manually. In order to do s
163
195
3. Configure your function to use that layer
164
196
4. Configure your function's environment variables correctly
165
197
198
+
[discrete]
199
+
[[aws-lambda-download-released]]
166
200
=== Download a Released Extension
167
201
168
202
The extension is released as a ZIP archive via https://github.com/elastic/apm-aws-lambda/releases[the GitHub releases page]. To download an archive, simply navigate to the latest version, and choose either the AMD64 or ARM64 release (depending on which architecture your Lambda function uses).
169
203
170
204
image:images/assets.png[image of assets tab in releases]
171
205
206
+
[discrete]
207
+
[[aws-lambda-publish-layer]]
172
208
=== Publish a Lambda layer
173
209
174
210
Next, you'll want to take that release ZIP file and publish it https://docs.aws.amazon.com/lambda/latest/dg/invocation-layers.html?icmpid=docs_lambda_help[as a Lambda layer]. A Lambda layer is a zip file archive that contains additional code or files for your Lambda function.
175
211
176
-
To do this, navigate the the Layers section of the AWS console, click the _Create layer_ button, and follow the prompts to upload the ZIP archive as a layer.
212
+
To do this, navigate to the Layers section of the AWS console, click the _Create layer_ button, and follow the prompts to upload the ZIP archive as a layer.
177
213
178
214
image:images/layers.png[image of layers section in the Amazon Console]
179
215
180
216
After publishing a layer, you'll receive a Version ARN. This ARN is the layer's unique identifier.
181
217
218
+
[discrete]
219
+
[[aws-lambda-configure-layer]]
182
220
=== Configure the Layer
183
221
184
222
Once you've published a layer, you'll need to configure your function to use that layer. To add a layer
@@ -189,6 +227,8 @@ Once you've published a layer, you'll need to configure your function to use tha
189
227
4. Enter the Version ARN of your layer in the _Specify an ARN_ text input
190
228
5. Click the _Add_ button
191
229
230
+
[discrete]
231
+
[[aws-lambda-configure-env]]
192
232
=== Configure your Environment Variables
193
233
194
234
Finally, once the layer's in place you'll need to configure a few environmental variables. To configure variables
@@ -198,25 +238,36 @@ Finally, once the layer's in place you'll need to configure a few environmental
198
238
3. Click on _Environment variables_
199
239
4. Add the necessary variables.
200
240
241
+
[discrete]
242
+
[[aws-lambda-variables]]
201
243
=== The Necessary Variables
202
244
245
+
[discrete]
246
+
[[aws-lambda-central_config]]
203
247
==== `ELASTIC_APM_CENTRAL_CONFIG`
204
248
205
249
The `ELASTIC_APM_CENTRAL_CONFIG` value _must_ be set to `false`. Central configuration does not work in a Lambda environment, and having this on will negatively impact the performance of your Lambda function.
206
250
251
+
[discrete]
252
+
[[aws-lambda-cloud_provider]]
207
253
==== `ELASTIC_APM_CLOUD_PROVIDER`
208
254
209
255
The `ELASTIC_APM_CLOUD_PROVIDER` value _must_ be set to `none`. Amazon's Cloud Metadata APIs are not available in an AWS Lambda environment, and attempting to fetch this data will negatively impact the performance of your Lambda function.
210
256
257
+
[discrete]
258
+
[[aws-lambda-lambda_apm_server]]
211
259
==== `ELASTIC_APM_LAMBDA_APM_SERVER`
212
260
213
261
The `ELASTIC_APM_LAMBDA_APM_SERVER` controls where the Lambda extension will ship data. This should be the URL of the final APM Server destination for your telemetry.
214
262
263
+
[discrete]
264
+
[[aws-lambda-apm_secret_token]]
215
265
==== `ELASTIC_APM_SECRET_TOKEN` or `ELASTIC_APM_API_KEY`
216
266
217
-
Either `ELASTIC_APM_API_KEY` or `ELASTIC_APM_SECRET_TOKEN` needs to be set. This controls the authentication method that extension uses when sending data to the URL configured via `ELASTIC_APM_LAMBDA_APM_SERVER`.
267
+
Either `ELASTIC_APM_API_KEY` or `ELASTIC_APM_SECRET_TOKEN` needs to be set. This controls the authentication method that the extension uses when sending data to the URL configured via `ELASTIC_APM_LAMBDA_APM_SERVER`.
218
268
269
+
[discrete]
270
+
[[aws-lambda-apm_server_url]]
219
271
==== `ELASTIC_APM_SERVER_URL`
220
272
221
273
This _must_ be configured to the value `http://localhost:8200`. This configuration field controls where your APM Agent sends data. The extension listens for data on `localhost:8200`.
0 commit comments