Skip to content

Commit cbcb421

Browse files
authored
Merge pull request #1 from baikonur-oss/init
Initialize repo
2 parents 8d9c0f1 + 0a26699 commit cbcb421

File tree

9 files changed

+663
-9
lines changed

9 files changed

+663
-9
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ venv/
1717

1818
### Others
1919
build/
20-
package.zip
20+
lambda_package.zip

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Baikonur
3+
Copyright (c) 2019 CyberAgent, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,93 @@
1-
# AWS %description% Terraform module
1+
# Amazon Kinesis to Kinesis log forwarding Terraform module
22

3-
Terraform module for %long_description%
3+
Terraform module and Lambda for saving JSON log records from Kinesis Data Streams to S3.
44

55
![terraform v0.11.x](https://img.shields.io/badge/terraform-v0.11.x-brightgreen.svg)
66

7-
## Usage
7+
## Prerequisites
8+
1. Records in Kinesis stream must be valid JSON data. Non-JSON data will be **ignored**.
9+
1. gzipped JSON, [CloudWatch Logs subscription filters log format](https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/logs/SubscriptionFilters.html) are supported.
10+
2. Broken JSON logs or logs without log type will be saved to S3 as `unknown`.
11+
2. JSON data must have the following keys (key names are modifiable via variables):
12+
1. `log_type`: Log type identifier. Used for applying log type whitelist
13+
3. Recommended keys (necessary if target stream has [lambda-kinesis-to-s3](https://github.com/baikonur-oss/terraform-aws-lambda-kinesis-to-s3) or other modules attached):
14+
1. `log_id`: Any unique identifier. Used to avoid file overwrites on S3. Also is useful to search for a specific log record.
15+
2. `time`: Any timestamp supported by [dateutil.parser.parse](https://dateutil.readthedocs.io/en/stable/parser.html#dateutil.parser.parse). ISO8601 with milli/microseconds recommended.
816

17+
## Usage
918
```HCL
10-
resource "aws_s3_bucket" "bucket" {
11-
bucket = "test"
19+
resource "aws_kinesis_stream" "stream" {
20+
name = "stream"
21+
shard_count = "1"
22+
retention_period = "24"
23+
}
24+
25+
resource "aws_kinesis_stream" "target" {
26+
name = "target"
27+
shard_count = "1"
28+
retention_period = "24"
29+
}
30+
31+
module "kinesis_forward" {
32+
source = "baikonur-oss/lambda-kinesis-forward/aws"
33+
34+
lambda_package_url = "https://github.com/baikonur-oss/terraform-aws-lambda-kinesis-forward/releases/download/v1.0.0/lambda_package.zip"
35+
name = "kinesis_forward"
36+
37+
memory = "1024"
38+
batch_size = "100"
39+
40+
source_stream_name = "${aws_kinesis_stream.source.name}"
41+
target_stream_name = "${aws_kinesis_stream.target.name}"
42+
43+
failed_log_s3_bucket = "failed-logs"
44+
failed_log_s3_prefix = "forward"
1245
}
1346
```
1447

48+
Warning: use same module and package versions!
49+
1550
### Version pinning
1651
#### Terraform Module Registry
17-
Use `version` parameter to pin to a specific version, or to specify a version constraint when pulling from [Terraform Module Registry](https://registry.terraform.io) (`source = baikonur-oss/%module_name%/aws`).
52+
Use `version` parameter to pin to a specific version, or to specify a version constraint when pulling from [Terraform Module Registry](https://registry.terraform.io) (`source = baikonur-oss/lambda-kinesis-forward/aws`).
1853
For more information, refer to [Module Versions](https://www.terraform.io/docs/configuration/modules.html#module-versions) section of Terraform Modules documentation.
1954

2055
#### GitHub URI
2156
Make sure to use `?ref=` version pinning in module source URI when pulling from GitHub.
2257
Pulling from GitHub is especially useful for development, as you can pin to a specific branch, tag or commit hash.
23-
Example: `source = github.com/baikonur-oss/%repo_name%?ref=v1.0.0`
58+
Example: `source = github.com/baikonur-oss/terraform-aws-lambda-kinesis-forward?ref=v1.0.0`
2459

2560
For more information on module version pinning, see [Selecting a Revision](https://www.terraform.io/docs/modules/sources.html#selecting-a-revision) section of Terraform Modules documentation.
2661

2762

2863
<!-- Documentation below is generated by pre-commit, do not overwrite manually -->
2964
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
65+
## Inputs
66+
67+
| Name | Description | Type | Default | Required |
68+
|------|-------------|:----:|:-----:|:-----:|
69+
| batch\_size | Maximum number of records passed for a single Lambda invocation | string | n/a | yes |
70+
| failed\_log\_s3\_bucket | S3 bucket name for saving failed logs (ES API errors etc.) | string | n/a | yes |
71+
| failed\_log\_s3\_prefix | Path prefix for failed logs | string | n/a | yes |
72+
| handler | Lambda Function handler (entrypoint) | string | `"main.handler"` | no |
73+
| lambda\_package\_url | Lambda package URL (see Usage in README) | string | n/a | yes |
74+
| log\_id\_field | Key name for unique log ID | string | `"log_id"` | no |
75+
| log\_retention\_in\_days | Lambda Function log retention in days | string | `"30"` | no |
76+
| log\_timestamp\_field | Key name for log timestamp | string | `"time"` | no |
77+
| log\_type\_field | Key name for log type | string | `"log_type"` | no |
78+
| log\_type\_field\_whitelist | Log type whitelist (if empty, all types will be processed) | list | `<list>` | no |
79+
| log\_type\_unknown\_prefix | Log type prefix for logs without log type field | string | `"unknown"` | no |
80+
| memory | Lambda Function memory in megabytes | string | `"256"` | no |
81+
| name | Resource name | string | n/a | yes |
82+
| runtime | Lambda Function runtime | string | `"python3.7"` | no |
83+
| source\_stream\_name | Source Kinesis Data Stream name | string | n/a | yes |
84+
| starting\_position | Kinesis ShardIterator type (see: https://docs.aws.amazon.com/kinesis/latest/APIReference/API_GetShardIterator.html ) | string | `"TRIM_HORIZON"` | no |
85+
| tags | Tags for Lambda Function | map | `<map>` | no |
86+
| target\_stream\_name | Target Kinesis Data Stream name | string | n/a | yes |
87+
| timeout | Lambda Function timeout in seconds | string | `"60"` | no |
88+
| timezone | tz database timezone name (e.g. Asia/Tokyo) | string | `"UTC"` | no |
89+
| tracing\_mode | X-Ray tracing mode (see: https://docs.aws.amazon.com/lambda/latest/dg/API_TracingConfig.html ) | string | `"PassThrough"` | no |
90+
3091
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3192

3293
## Contributing

build.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
echo "[1/5] Activating venv"
6+
7+
if [[ ! -f venv/bin/activate ]]; then
8+
echo "Could not find venv! Create a venv and try again."
9+
exit -1
10+
fi
11+
12+
source venv/bin/activate
13+
14+
echo "[2/5] Cleaning cache"
15+
rm -rf build
16+
rm -rf lambda_package.zip
17+
18+
echo "[3/5] Creating local copy"
19+
mkdir -p build
20+
cp lambda/*.py build/
21+
cp lambda/requirements-deploy.txt build/
22+
23+
echo "[4/5] pip install"
24+
cd build
25+
docker run --rm -v $(pwd):/root/p python:3.7 pip3 install -r /root/p/requirements-deploy.txt -t /root/p/ > /dev/null
26+
27+
echo "[5/5] Compiling and making zip package"
28+
python -m compileall .
29+
zip -r9 ../lambda_package.zip ./ -x ".*" > /dev/null
30+
cd ..
31+
32+
echo "Finished!"

0 commit comments

Comments
 (0)