Skip to content

Commit e0a636f

Browse files
committed
Add AWS Lambda logs integration with Rotel
1 parent 6b4acf8 commit e0a636f

File tree

4 files changed

+331
-1
lines changed

4 files changed

+331
-1
lines changed
Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
---
2+
slug: /use-cases/observability/clickstack/integrations/aws-lambda
3+
title: 'Monitoring AWS Lambda Logs with ClickStack'
4+
sidebar_label: 'AWS Lambda Logs'
5+
pagination_prev: null
6+
pagination_next: null
7+
description: 'Monitoring AWS Lambda Logs with ClickStack'
8+
doc_type: 'guide'
9+
keywords: ['AWS', 'Lambda', 'OTEL', 'ClickStack', 'logs', 'CloudWatch']
10+
---
11+
12+
import Image from '@theme/IdealImage';
13+
import useBaseUrl from '@docusaurus/useBaseUrl';
14+
import log_view from '@site/static/images/clickstack/lambda/lambda-log-view.png';
15+
import log from '@site/static/images/clickstack/lambda/lambda-log.png';
16+
import { TrackedLink } from '@site/src/components/GalaxyTrackedLink/GalaxyTrackedLink';
17+
18+
# Monitoring AWS Lambda Logs with ClickStack {#lambda-clickstack}
19+
20+
:::note[TL;DR]
21+
This guide shows you how to monitor AWS Lambda functions with ClickStack by using the Rotel Lambda Extension to collect and forward function logs, extension logs, and OpenTelemetry data directly to ClickHouse. You'll learn how to:
22+
23+
- Deploy the Rotel Lambda Extension layer to your Lambda functions
24+
- Configure the extension to export logs and traces to ClickStack
25+
- Optionally disable CloudWatch Logs to reduce costs
26+
- Use pre-built dashboards to visualize Lambda metrics (invocations, errors, duration, cold starts)
27+
28+
This approach can **significantly reduce your Lambda observability costs** by bypassing CloudWatch Logs entirely.
29+
30+
Time Required: 5-10 minutes
31+
:::
32+
33+
## Integration with existing Lambda functions {#existing-lambda}
34+
35+
This section covers configuring your existing AWS Lambda functions to send logs and traces to ClickStack using the Rotel Lambda Extension.
36+
37+
### Prerequisites {#prerequisites}
38+
- ClickStack instance running
39+
- AWS Lambda function(s) to monitor
40+
- AWS CLI configured with appropriate permissions
41+
- Lambda execution role with permissions to add layers
42+
43+
<VerticalStepper headerLevel="h4">
44+
45+
#### Choose the appropriate Rotel Lambda Extension layer {#choose-layer}
46+
47+
The [Rotel Lambda Extension](https://github.com/streamfold/rotel-lambda-extension) is available as a pre-built AWS Lambda layer. Choose the layer ARN that matches your Lambda function's architecture:
48+
49+
| Architecture | ARN Pattern | Latest Version |
50+
|--------------|-------------|----------------|
51+
| x86-64/amd64 | `arn:aws:lambda:{region}:418653438961:layer:rotel-extension-amd64-alpha:{version}` | ![Version](https://img.shields.io/github/v/release/streamfold/rotel-lambda-extension?filter=*alpha&label=version&labelColor=%2338BDF8&color=%23312E81&cacheSeconds=600) |
52+
| arm64 | `arn:aws:lambda:{region}:418653438961:layer:rotel-extension-arm64-alpha:{version}` | ![Version](https://img.shields.io/github/v/release/streamfold/rotel-lambda-extension?filter=*alpha&label=version&labelColor=%2338BDF8&color=%23312E81&cacheSeconds=600) |
53+
54+
**Available regions:**
55+
- us-east-{1, 2}, us-west-{1, 2}
56+
- eu-central-1, eu-north-1, eu-west-{1, 2, 3}
57+
- ca-central-1
58+
- ap-southeast-{1, 2}, ap-northeast-{1, 2}
59+
- ap-south-1
60+
- sa-east-1
61+
62+
#### Add the Rotel layer to your Lambda function {#add-layer}
63+
64+
_In these examples replace `{arch}`, `{region}`, and `{version}` with the appropriate values above._
65+
66+
##### Option 1: AWS Console {#console}
67+
68+
1. Open the AWS Lambda console
69+
2. Navigate to your Lambda function
70+
3. Scroll to the **Layers** section and click **Add a layer**
71+
4. Select **Specify an ARN**
72+
5. Enter the Rotel layer ARN:
73+
```
74+
arn:aws:lambda:{region}:418653438961:layer:rotel-extension-{arch}-alpha:{version}
75+
```
76+
6. Click **Add**
77+
78+
##### Option 2: AWS CLI {#cli}
79+
80+
```bash
81+
aws lambda update-function-configuration \
82+
--function-name my-function \
83+
--layers arn:aws:lambda:{region}:418653438961:layer:rotel-extension-{arch}-alpha:{version}
84+
```
85+
86+
##### Option 3: AWS SAM {#sam}
87+
88+
```yaml
89+
Resources:
90+
MyFunction:
91+
Type: AWS::Serverless::Function
92+
Properties:
93+
# ... other configuration ...
94+
Layers:
95+
- arn:aws:lambda:{version}:418653438961:layer:rotel-extension-{arch}-alpha:{version}
96+
```
97+
98+
#### Configure the extension to export to ClickStack {#configure-extension}
99+
100+
The Rotel Lambda Extension is configured using environment variables. You need to configure the OTLP exporter endpoint to point to your ClickStack instance. The examples assume your AWS Lambda function is able to reach the ClickStack instance.
101+
102+
##### Basic Configuration (Environment Variables) {#basic-config}
103+
104+
Add these environment variables to your Lambda function:
105+
106+
```bash
107+
# Required: ClickStack OTLP endpoint
108+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
109+
110+
# Optional: Authentication headers
111+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=<YOUR_INGESTION_API_KEY>"
112+
113+
# Optional: Service name (defaults to Lambda function name)
114+
ROTEL_OTEL_RESOURCE_ATTRIBUTES="service.name=my-lambda-api,service.version=1.0.0"
115+
```
116+
117+
##### Advanced Configuration (Using .env file) {#advanced-config}
118+
119+
For more complex configurations, create a `rotel.env` file in your Lambda function bundle:
120+
121+
**rotel.env:**
122+
```shell
123+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
124+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=<YOUR_INGESTION_API_KEY>"
125+
ROTEL_OTEL_RESOURCE_ATTRIBUTES="service.name=my-lambda-api,deployment.environment=production"
126+
```
127+
128+
Then set the environment variable to point to this file:
129+
```bash
130+
ROTEL_ENV_FILE=/var/task/rotel.env
131+
```
132+
133+
##### Using AWS Secrets Manager or Parameter Store {#secrets}
134+
135+
For production deployments, store sensitive values like API keys in AWS Secrets Manager or Parameter Store:
136+
137+
**AWS Secrets Manager Example:**
138+
```shell
139+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
140+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=${arn:aws:secretsmanager:us-east-1:123456789012:secret:clickstack-api-key-abc123}"
141+
```
142+
143+
**AWS Parameter Store Example:**
144+
```shell
145+
ROTEL_OTLP_EXPORTER_ENDPOINT=https://clickstack.example.com:4317
146+
ROTEL_OTLP_EXPORTER_CUSTOM_HEADERS="Authorization=${arn:aws:ssm:us-east-1:123456789012:parameter/clickstack-api-key}"
147+
```
148+
149+
**Required IAM Permissions:**
150+
151+
Add these permissions to your Lambda execution role:
152+
153+
For Secrets Manager:
154+
```json
155+
{
156+
"Version": "2012-10-17",
157+
"Statement": [
158+
{
159+
"Effect": "Allow",
160+
"Action": [
161+
"secretsmanager:GetSecretValue",
162+
"secretsmanager:BatchGetSecretValue"
163+
],
164+
"Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:clickstack-api-key-*"
165+
}
166+
]
167+
}
168+
```
169+
170+
For Parameter Store:
171+
```json
172+
{
173+
"Version": "2012-10-17",
174+
"Statement": [
175+
{
176+
"Effect": "Allow",
177+
"Action": [
178+
"ssm:GetParameters"
179+
],
180+
"Resource": "arn:aws:ssm:us-east-1:123456789012:parameter/clickstack-api-key"
181+
}
182+
]
183+
}
184+
```
185+
186+
:::note
187+
AWS API calls for secret retrieval add 100-150ms to cold start latency. Secrets are retrieved in batches (up to 10) and only on initialization, so subsequent invocations are not impacted.
188+
:::
189+
190+
#### Test the integration {#test-integration}
191+
192+
Invoke your Lambda function to verify logs are being sent to ClickStack:
193+
194+
```bash
195+
aws lambda invoke \
196+
--function-name my-function \
197+
--payload '{"test": "data"}' \
198+
response.json
199+
```
200+
201+
Check the Lambda logs for any errors:
202+
```bash
203+
aws logs tail /aws/lambda/my-function --follow
204+
```
205+
206+
#### Verify logs in HyperDX {#verify-logs}
207+
208+
Once configured, log into HyperDX (ClickStack's UI) and verify that logs are flowing:
209+
210+
<Image img={log_view} alt="Lambda Log View"/>
211+
212+
<Image img={log} alt="Lambda Log Detail"/>
213+
214+
Look for these key attributes in the logs:
215+
- `service.name`: Your Lambda function name
216+
- `faas.name`: AWS Lambda function name
217+
- `faas.invocation_id`: Unique invocation ID
218+
- `cloud.provider`: "aws"
219+
- `cloud.platform`: "aws_lambda"
220+
221+
</VerticalStepper>
222+
223+
## Disabling CloudWatch Logs (Cost Optimization) {#disable-cloudwatch}
224+
225+
By default, AWS Lambda sends all logs to CloudWatch Logs, which can be expensive at scale. Once you've verified that logs are flowing to ClickStack, you can disable CloudWatch logging to reduce costs.
226+
227+
<VerticalStepper headerLevel="h4">
228+
229+
#### Remove CloudWatch permissions from the execution role {#remove-permissions}
230+
231+
1. Open the AWS Console and navigate to **AWS Lambda**
232+
2. Navigate to your Lambda function
233+
3. Select **Configuration****Permissions**
234+
4. Click the execution role name to open the IAM console
235+
5. Edit the role and remove any `logs:*` actions:
236+
- If using a custom policy, edit to remove `logs:CreateLogGroup`, `logs:CreateLogStream`, and `logs:PutLogEvents`
237+
- If using the AWS managed policy `AWSLambdaBasicExecutionRole`, remove it from the role
238+
6. Save the role
239+
240+
#### Verify CloudWatch logging is disabled {#verify-disabled}
241+
242+
Invoke your function again and verify that:
243+
1. No new CloudWatch log streams are created
244+
2. Logs continue to appear in ClickStack/HyperDX
245+
246+
```bash
247+
# This should show no new log streams after the policy change
248+
aws logs describe-log-streams \
249+
--log-group-name /aws/lambda/my-function \
250+
--order-by LastEventTime \
251+
--descending \
252+
--max-items 5
253+
```
254+
255+
</VerticalStepper>
256+
257+
## Adding OpenTelemetry auto-instrumentation {#auto-instrumentation}
258+
259+
The Rotel Lambda Extension works seamlessly with OpenTelemetry auto-instrumentation layers to collect distributed traces and metrics in addition to logs.
260+
261+
<VerticalStepper headerLevel="h4">
262+
263+
#### Choose your language instrumentation layer {#choose-instrumentation}
264+
265+
AWS provides OpenTelemetry auto-instrumentation layers for multiple languages:
266+
267+
| Language | Layer ARN Pattern |
268+
|----------|-------------------|
269+
| Node.js | `arn:aws:lambda:{region}:901920570463:layer:aws-otel-nodejs-{arch}-ver-{version}` |
270+
| Python | `arn:aws:lambda:{region}:901920570463:layer:aws-otel-python-{arch}-ver-{version}` |
271+
| Java | `arn:aws:lambda:{region}:901920570463:layer:aws-otel-java-agent-{arch}-ver-{version}` |
272+
273+
Find the latest versions in the [AWS OpenTelemetry Lambda repository](https://github.com/aws-observability/aws-otel-lambda).
274+
275+
#### Add both layers to your function {#add-both-layers}
276+
277+
Add **both** the Rotel extension layer and the instrumentation layer:
278+
279+
```bash
280+
aws lambda update-function-configuration \
281+
--function-name my-function \
282+
--layers \
283+
arn:aws:lambda:{region}:418653438961:layer:rotel-extension-{arch}-alpha:{version} \
284+
arn:aws:lambda:{region}:901920570463:layer:aws-otel-nodejs-{arch}-ver-1-30-2:1
285+
```
286+
287+
#### Configure the auto-instrumentation {#configure-instrumentation}
288+
289+
Set the `AWS_LAMBDA_EXEC_WRAPPER` environment variable to enable auto-instrumentation:
290+
291+
**For Node.js:**
292+
```bash
293+
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
294+
```
295+
296+
**For Python:**
297+
```bash
298+
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-instrument
299+
```
300+
301+
**For Java:**
302+
```bash
303+
AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler
304+
```
305+
306+
#### Verify traces in HyperDX {#verify-traces}
307+
308+
After invoking your function:
309+
310+
1. Navigate to the **Traces** view in HyperDX
311+
2. You should see traces with spans from your Lambda function
312+
3. Traces will be correlated with logs via `trace_id` and `span_id` attributes
313+
314+
</VerticalStepper>
315+
316+
## Example applications {#examples}
317+
318+
Checkout the example Python app demonstrating the Rotel Lambda Extension:
319+
320+
- **[Python + ClickHouse](https://github.com/streamfold/python-aws-lambda-clickhouse-example)**: Python application with manual OpenTelemetry instrumentation, sending traces and logs directly to ClickHouse
321+
322+
## Join the Rotel community
323+
324+
If you have questions about Rotel, please join the [Rotel Discord server](https://rotel.dev) and share your feedback or questions. Check out the [Rotel Lambda Extension](https://github.com/streamfold/rotel-lambda-extension) to contribute any improvements.
325+
326+
## Additional resources {#resources}
327+
328+
- **[Rotel Lambda Extension](https://github.com/streamfold/rotel-lambda-extension)**: Source code and detailed documentation
329+
- **[Rotel Core](https://github.com/streamfold/rotel)**: The lightweight OTEL data plane powering the extension

docs/use-cases/observability/clickstack/integration-examples/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ Several of these integration guides use ClickStack's built-in OpenTelemetry Coll
2525
| [PostgreSQL Logs](/use-cases/observability/clickstack/integrations/postgresql-logs) | Quick start guide for PostgreSQL Logs |
2626
| [PostgreSQL Metrics](/use-cases/observability/clickstack/integrations/postgresql-metrics) | Quick start guide for PostgreSQL Metrics |
2727
| [Redis Logs](/use-cases/observability/clickstack/integrations/redis) | Quick start guide for Redis Logs |
28-
| [Redis Metrics](/use-cases/observability/clickstack/integrations/redis-metrics) | Quick start guide for Redis Metrics |
28+
| [Redis Metrics](/use-cases/observability/clickstack/integrations/redis-metrics) | Quick start guide for Redis Metrics |
29+
| [AWS Lambda Logs](/use-cases/observability/clickstack/integrations/aws-lambda) | Quick start guide for AWS Lambda Logs |
187 KB
Loading
105 KB
Loading

0 commit comments

Comments
 (0)