|
1 |
| -# AWS %description% Terraform module |
| 1 | +# Amazon Kinesis to Kinesis log forwarding Terraform module |
2 | 2 |
|
3 |
| -Terraform module for %long_description% |
| 3 | +Terraform module and Lambda for saving JSON log records from Kinesis Data Streams to S3. |
4 | 4 |
|
5 | 5 | 
|
6 | 6 |
|
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. |
8 | 16 |
|
| 17 | +## Usage |
9 | 18 | ```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" |
12 | 45 | }
|
13 | 46 | ```
|
14 | 47 |
|
| 48 | +Warning: use same module and package versions! |
| 49 | + |
15 | 50 | ### Version pinning
|
16 | 51 | #### 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`). |
18 | 53 | For more information, refer to [Module Versions](https://www.terraform.io/docs/configuration/modules.html#module-versions) section of Terraform Modules documentation.
|
19 | 54 |
|
20 | 55 | #### GitHub URI
|
21 | 56 | Make sure to use `?ref=` version pinning in module source URI when pulling from GitHub.
|
22 | 57 | 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` |
24 | 59 |
|
25 | 60 | 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.
|
26 | 61 |
|
27 | 62 |
|
28 | 63 | <!-- Documentation below is generated by pre-commit, do not overwrite manually -->
|
29 | 64 | <!-- 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 | + |
30 | 91 | <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
|
31 | 92 |
|
32 | 93 | ## Contributing
|
|
0 commit comments