Firehose transformation Lambda functions that enrich CloudWatch data with AWS resource tags and properties before delivery to Better Stack. They are written in Rust and run on the OS-only provided.al2023 runtime on arm64: each binary is zipped as bootstrap.
See the main README for an overview or the CloudFormation deployment guide for deployment instructions.
Enriches CloudWatch Metric Stream data with resource tags and properties.
Input: Base64-encoded NDJSON (newline-delimited JSON) from Firehose
Output: Enriched NDJSON with tags and properties fields added
Supported Namespaces:
AWS/EC2- Instance tags + properties (type, family, size, architecture, AZ, lifecycle)AWS/EBS- Volume tags + properties (type, size, IOPS, throughput)AWS/RDS- Database tags + properties (class, engine, version, storage type)AWS/Lambda- Function tags + properties (runtime, memory, timeout, architecture)AWS/DynamoDB- Table tagsAWS/SQS- Queue tagsAWS/SNS- Topic tagsAWS/S3- Bucket tagsAWS/ELB,AWS/ApplicationELB,AWS/NetworkELB- Load balancer tags
Enriches CloudWatch Logs with resource tags extracted from log group/stream names.
Input: Base64-encoded gzip-compressed CloudWatch Logs subscription data
Output: Enriched logs with tags, resource_name, environment, and team fields
Supported Log Patterns:
/aws/lambda/{function-name}- Lambda function tags/aws/rds/instance/{db-instance}/{type}- RDS instance tagsRDSOSMetrics- RDS Enhanced Monitoring (extractsinstanceIDfrom message body)/ecs/{cluster}/...- ECS cluster tags/aws/api-gateway/{api-id}- API Gateway tags- Log streams containing
i-xxxxxxxxx- EC2 instance tags
Environment variables (set via CloudFormation):
| Variable | Default | Description |
|---|---|---|
CACHE_TTL_MINUTES |
10 |
How long to cache tags/properties before refreshing |
ACCOUNT_ID |
(required) | AWS account ID for ARN construction |
AWS_REGION |
us-east-1 |
AWS region (auto-set by Lambda runtime) |
DEBUG |
false |
Enable verbose logging |
CloudWatch Metrics ─┐
├─> Firehose ─> Lambda (enrichment) ─> Firehose -> Better Stack
CloudWatch Logs ────┘
Both functions:
- Receive batched records from Kinesis Firehose
- Extract resource identifiers (ARNs) from the data
- Batch-fetch tags via the Resource Groups Tagging API (max 100 ARNs per call)
- Cache tags in-memory to minimize API calls
- Return enriched records to Firehose for delivery
The crate is lambda/: src/logs.rs and src/metrics.rs hold each function's logic, src/tags.rs the shared tag cache, src/aws.rs the AWS SDK calls, and src/bin/ the two Lambda entry points.
cd lambda
cargo testThe tests replace the AWS APIs with an in-memory fake (src/fake.rs), so they need no credentials.
lambda/build.shIt builds both functions inside Amazon Linux 2023 on an arm64 host with Docker, so the binaries link against the glibc the Lambda runtime has, and writes lambda/dist/firehose_logs_tag_enrichment.zip and lambda/dist/firehose_metrics_tag_enrichment.zip. The E2E workflow builds them on every pull request and keeps them as the lambda-zips artifact; the Release workflow attaches them to the release.
The template deploys the functions from <version>/<function>.zip in the regional S3 buckets (better-stack-lambda-{region}), where <version> is the release the template was stamped with. The E2E workflow builds the zips on every pull request, uploads them under the run id to a bucket of its own and points its copy of the template at it. See the CloudFormation README for deployment commands.