Firehose transformation Lambda functions that enrich CloudWatch data with AWS resource tags and properties before delivery to Better Stack.
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
bundle installbundle exec rspec spec/lambda/Or run specific tests:
bundle exec rspec spec/lambda/firehose_metrics_tag_enrichment_spec.rb
bundle exec rspec spec/lambda/firehose_logs_tag_enrichment_spec.rbaws-sdk-resourcegroupstaggingapi- Tag lookupsaws-sdk-ec2- EC2/EBS property lookupsaws-sdk-rds- RDS property lookupsaws-sdk-lambda- Lambda property lookups
Lambda code is deployed via CloudFormation from regional S3 buckets (better-stack-lambda-{region}), referenced in the CloudFormation stack. See the CloudFormation README for deployment commands.