Skip to content

Commit 1e2f28e

Browse files
Improve READMEs
1 parent c400835 commit 1e2f28e

File tree

4 files changed

+115
-29
lines changed

4 files changed

+115
-29
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Better Stack AWS Integration
22

3-
This repository contains all Better Stack CloudFormation stacks and Lambdas for the Better Stack AWS Integration.
3+
This repository contains CloudFormation stacks and Lambda functions for streaming AWS CloudWatch data to Better Stack.
4+
5+
## Repository Structure
6+
7+
| Directory | Description |
8+
|-----------|-------------|
9+
| [cloudformation/full/](cloudformation/full/README.md) | CloudFormation template and deployment guide |
10+
| [lambda/](lambda/README.md) | Firehose transformation Lambda functions |
411

512
## Getting Started
613

7-
To get started with Better Stack on AWS, [create a new AWS Source in Better Stack Telemetry](https://telemetry.betterstack.com/team/t0/sources/new?platform=aws).
14+
To get started with Better Stack on AWS, [create a new AWS Source in Better Stack](https://telemetry.betterstack.com/team/t0/sources/new?platform=aws).
15+
16+
For deployment instructions, see the [CloudFormation deployment guide](cloudformation/full/README.md).
817

918
## Ingested Data
1019

1120
When you deploy our CloudFormation stack you get:
1221

1322
- Automatic ingestion of all CloudWatch metrics into Better Stack.
1423
- Support for RDS Enhanced Metrics (RDSOS)
15-
- Detection and per-log-group optional ingestion of all Cloudwatch log groups.
16-
- Automatic integration with AWS X-Ray, ingest traces into Better Stack Telemetry and view your traces.
24+
- Detection and per-log-group optional ingestion of all CloudWatch log groups.
25+
- Automatic integration with AWS X-Ray for trace ingestion.
26+
- Optional CloudTrail audit log forwarding.

cloudformation/full/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Stream AWS CloudWatch metrics, logs, and optionally X-Ray traces and CloudTrail audit logs to Better Stack via Kinesis Data Firehose.
44

5+
See the [main README](../../README.md) for an overview or the [Lambda documentation](../../lambda/README.md) for details on deployed lambdas.
6+
57
## Prerequisites
68

79
1. **Better Stack Account** - Sign up at [betterstack.com](https://betterstack.com)
@@ -111,7 +113,7 @@ After deployment, provide these values to Better Stack:
111113

112114
## Tag Enrichment
113115

114-
When `EnableTagEnrichment=true`, Lambda functions enrich metrics and logs with AWS resource tags.
116+
When `EnableTagEnrichment=true`, [Lambda functions](../../lambda/README.md) enrich metrics and logs with AWS resource tags.
115117

116118
**Metrics enrichment** adds tags from:
117119
- EC2 instances
@@ -130,7 +132,7 @@ When `EnableTagEnrichment=true`, Lambda functions enrich metrics and logs with A
130132
- `/ecs/{cluster}/...` -> ECS tags
131133
- `/aws/api-gateway/{api-id}` -> API Gateway tags
132134

133-
Lambda code is loaded from regional S3 buckets (`better-stack-lambda-{region}`).
135+
See the [Lambda README](../../lambda/README.md) for implementation details. Lambda code is deployed from regional S3 buckets (`better-stack-lambda-{region}`).
134136

135137
## Stack Outputs
136138

cloudformation/full/better-stack-full.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Resources:
9898
Type: AWS::IAM::Role
9999
Condition: ShouldCreateGlobalResources
100100
Properties:
101-
RoleName: !Sub 'better-stack-firehose-role'
101+
RoleName: !Sub 'betterstack-firehose-role'
102102
AssumeRolePolicyDocument:
103103
Version: '2012-10-17'
104104
Statement:
@@ -121,8 +121,8 @@ Resources:
121121
- s3:GetBucketLocation
122122
- s3:ListBucket
123123
Resource:
124-
- !Sub 'arn:aws:s3:::better-stack-firehose-${AWS::AccountId}-*'
125-
- !Sub 'arn:aws:s3:::better-stack-firehose-${AWS::AccountId}-*/*'
124+
- !Sub 'arn:aws:s3:::betterstack-firehose-${AWS::AccountId}-*'
125+
- !Sub 'arn:aws:s3:::betterstack-firehose-${AWS::AccountId}-*/*'
126126
- PolicyName: CloudWatchLogsPermissions
127127
PolicyDocument:
128128
Version: '2012-10-17'
@@ -134,7 +134,7 @@ Resources:
134134
- logs:CreateLogStream
135135
- logs:CreateLogGroup
136136
Resource:
137-
- !Sub 'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/kinesisfirehose/better-stack-*:*'
137+
- !Sub 'arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/kinesisfirehose/betterstack-*:*'
138138
Tags:
139139
- Key: Solution
140140
Value: BetterStack
@@ -144,7 +144,7 @@ Resources:
144144
Type: AWS::IAM::Role
145145
Condition: ShouldCreateGlobalResources
146146
Properties:
147-
RoleName: !Sub 'better-stack-metric-stream-role'
147+
RoleName: !Sub 'betterstack-metric-stream-role'
148148
AssumeRolePolicyDocument:
149149
Version: '2012-10-17'
150150
Statement:
@@ -162,7 +162,7 @@ Resources:
162162
Action:
163163
- firehose:PutRecord
164164
- firehose:PutRecordBatch
165-
Resource: !Sub 'arn:aws:firehose:*:${AWS::AccountId}:deliverystream/better-stack-metrics'
165+
Resource: !Sub 'arn:aws:firehose:*:${AWS::AccountId}:deliverystream/betterstack-metrics'
166166
Tags:
167167
- Key: Solution
168168
Value: BetterStack
@@ -172,7 +172,7 @@ Resources:
172172
Type: AWS::IAM::Role
173173
Condition: ShouldCreateGlobalResources
174174
Properties:
175-
RoleName: !Sub 'better-stack-logs-subscription-role'
175+
RoleName: !Sub 'betterstack-logs-subscription-role'
176176
AssumeRolePolicyDocument:
177177
Version: '2012-10-17'
178178
Statement:
@@ -193,7 +193,7 @@ Resources:
193193
Action:
194194
- firehose:PutRecord
195195
- firehose:PutRecordBatch
196-
Resource: !Sub 'arn:aws:firehose:*:${AWS::AccountId}:deliverystream/better-stack-logs'
196+
Resource: !Sub 'arn:aws:firehose:*:${AWS::AccountId}:deliverystream/betterstack-logs'
197197
Tags:
198198
- Key: Solution
199199
Value: BetterStack
@@ -203,7 +203,7 @@ Resources:
203203
Type: AWS::IAM::Role
204204
Condition: CreateTagEnrichmentLambdaRole
205205
Properties:
206-
RoleName: !Sub 'better-stack-tag-enrichment-role'
206+
RoleName: !Sub 'betterstack-tag-enrichment-role'
207207
AssumeRolePolicyDocument:
208208
Version: '2012-10-17'
209209
Statement:
@@ -252,7 +252,7 @@ Resources:
252252
Type: AWS::IAM::Role
253253
Condition: ShouldCreateGlobalResources
254254
Properties:
255-
RoleName: !Sub 'better-stack-integration-role'
255+
RoleName: !Sub 'betterstack-integration-role'
256256
AssumeRolePolicyDocument:
257257
Version: '2012-10-17'
258258
Statement:
@@ -385,7 +385,7 @@ Resources:
385385
Effect: Allow
386386
Action:
387387
- iam:PassRole
388-
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:role/better-stack-logs-subscription-role'
388+
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:role/betterstack-logs-subscription-role'
389389
Tags:
390390
- Key: Solution
391391
Value: BetterStack

lambda/README.md

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,98 @@
11
# Lambda Functions
22

3-
This directory contains AWS Lambda functions for Kinesis Firehose data transformation.
3+
Firehose transformation Lambda functions that enrich CloudWatch data with AWS resource tags and properties before delivery to Better Stack.
4+
5+
See the [main README](../README.md) for an overview or the [CloudFormation deployment guide](../cloudformation/full/README.md) for deployment instructions.
46

57
## Functions
68

7-
| Function | Description |
8-
|----------|-------------|
9-
| `firehose_logs_tag_enrichment.rb` | Enriches CloudWatch Logs with AWS resource tags before delivery |
10-
| `firehose_metrics_tag_enrichment.rb` | Enriches CloudWatch Metrics with AWS resource tags before delivery |
9+
### firehose_metrics_tag_enrichment.rb
1110

12-
## Deployment
11+
Enriches CloudWatch Metric Stream data with resource tags and properties.
12+
13+
**Input:** Base64-encoded NDJSON (newline-delimited JSON) from Firehose
14+
**Output:** Enriched NDJSON with `tags` and `properties` fields added
15+
16+
**Supported Namespaces:**
17+
- `AWS/EC2` - Instance tags + properties (type, family, size, architecture, AZ, lifecycle)
18+
- `AWS/EBS` - Volume tags + properties (type, size, IOPS, throughput)
19+
- `AWS/RDS` - Database tags + properties (class, engine, version, storage type)
20+
- `AWS/Lambda` - Function tags + properties (runtime, memory, timeout, architecture)
21+
- `AWS/DynamoDB` - Table tags
22+
- `AWS/SQS` - Queue tags
23+
- `AWS/SNS` - Topic tags
24+
- `AWS/S3` - Bucket tags
25+
- `AWS/ELB`, `AWS/ApplicationELB`, `AWS/NetworkELB` - Load balancer tags
26+
27+
### firehose_logs_tag_enrichment.rb
28+
29+
Enriches CloudWatch Logs with resource tags extracted from log group/stream names.
30+
31+
**Input:** Base64-encoded gzip-compressed CloudWatch Logs subscription data
32+
**Output:** Enriched logs with `tags`, `resource_name`, `environment`, and `team` fields
1333

14-
These Lambda functions are automatically provisioned by the CloudFormation stack when `EnableTagEnrichment` is set to `true`. The stack handles packaging, deployment, and IAM permissions required for the Resource Groups Tagging API integration.
34+
**Supported Log Patterns:**
35+
- `/aws/lambda/{function-name}` - Lambda function tags
36+
- `/aws/rds/instance/{db-instance}/{type}` - RDS instance tags
37+
- `RDSOSMetrics` - RDS Enhanced Monitoring (extracts `instanceID` from message body)
38+
- `/ecs/{cluster}/...` - ECS cluster tags
39+
- `/aws/api-gateway/{api-id}` - API Gateway tags
40+
- Log streams containing `i-xxxxxxxxx` - EC2 instance tags
1541

16-
Lambda packages are hosted in regional S3 buckets following the pattern:
42+
## Configuration
43+
44+
Environment variables (set via CloudFormation):
45+
46+
| Variable | Default | Description |
47+
|----------|---------|-------------|
48+
| `CACHE_TTL_MINUTES` | `10` | How long to cache tags/properties before refreshing |
49+
| `ACCOUNT_ID` | (required) | AWS account ID for ARN construction |
50+
| `AWS_REGION` | `us-east-1` | AWS region (auto-set by Lambda runtime) |
51+
| `DEBUG` | `false` | Enable verbose logging |
52+
53+
## Architecture
1754

1855
```
19-
s3://better-stack-lambda-${AWS::Region}/<function>.zip
56+
CloudWatch Metrics ─┐
57+
├─> Firehose ─> Lambda (enrichment) ─> Firehose -> Better Stack
58+
CloudWatch Logs ────┘
2059
```
2160

22-
For example, in `us-east-1`:
23-
- `s3://better-stack-lambda-us-east-1/firehose_metrics_tag_enrichment.zip`
24-
- `s3://better-stack-lambda-us-east-1/firehose_logs_tag_enrichment.zip`
61+
Both functions:
62+
1. Receive batched records from Kinesis Firehose
63+
2. Extract resource identifiers (ARNs) from the data
64+
3. Batch-fetch tags via the Resource Groups Tagging API (max 100 ARNs per call)
65+
4. Cache tags in-memory to minimize API calls
66+
5. Return enriched records to Firehose for delivery
67+
68+
## Local Development
69+
70+
### Prerequisites
71+
72+
```bash
73+
bundle install
74+
```
75+
76+
### Running Tests
77+
78+
```bash
79+
bundle exec rspec spec/lambda/
80+
```
81+
82+
Or run specific tests:
83+
84+
```bash
85+
bundle exec rspec spec/lambda/firehose_metrics_tag_enrichment_spec.rb
86+
bundle exec rspec spec/lambda/firehose_logs_tag_enrichment_spec.rb
87+
```
88+
89+
### Dependencies
90+
91+
- `aws-sdk-resourcegroupstaggingapi` - Tag lookups
92+
- `aws-sdk-ec2` - EC2/EBS property lookups
93+
- `aws-sdk-rds` - RDS property lookups
94+
- `aws-sdk-lambda` - Lambda property lookups
95+
96+
## Deployment
97+
98+
Lambda code is deployed via CloudFormation from regional S3 buckets (`better-stack-lambda-{region}`), referenced in the CloudFormation stack. See the [CloudFormation README](../cloudformation/full/README.md) for deployment commands.

0 commit comments

Comments
 (0)