|
1 |
| -## Amazon Ecs Firelens Examples |
| 1 | +## Amazon ECS FireLens Examples |
2 | 2 |
|
3 | 3 | Sample logging architectures for FireLens on Amazon ECS and AWS Fargate.
|
4 | 4 |
|
| 5 | +### Contributing |
| 6 | + |
| 7 | +We want examples of as many use cases in this repository as possible! Submit a Pull Request if you would like to add something. |
| 8 | + |
| 9 | +### Fluent Bit Examples |
| 10 | + |
| 11 | +* [Send to CloudWatch Logs](examples/fluent-bit/cloudwatchlogs) |
| 12 | +* [Send to Kinesis Data Firehose](examples/fluent-bit/kinesis-firehose) |
| 13 | +* [Enable Debug Logging](examples/fluent-bit/enable-debug-logging) |
| 14 | +* [Forward to a Fluentd or Fluent Bit Log Aggregator](examples/fluent-bit/forward-to-aggregator) |
| 15 | +* [Parse Serialized JSON](examples/fluent-bit/parse-json) |
| 16 | +* [Parse common log formats](examples/fluent-bit/parse-common-log-formats) |
| 17 | +* [Send to multiple destinations](examples/fluent-bit/send-to-multiple-destinations) |
| 18 | +* [Add custom metadata to logs](examples/fluent-bit/add-keys) |
| 19 | + |
| 20 | +### Fluentd Examples |
| 21 | + |
| 22 | +TODO |
| 23 | + |
| 24 | +### Setup for the examples |
| 25 | + |
| 26 | +Before you use FireLens, familiarize yourself with [Amazon ECS](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_GetStarted_EC2.html) and with the [FireLens documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html). |
| 27 | + |
| 28 | +In order to use these examples, you will need the following IAM resources: |
| 29 | +* A [Task IAM Role](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html) with permissions to send logs to your log destination. Each of the examples in this repository that needs additional permissions has a sample policy. |
| 30 | +* A [Task Execution Role](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html). This role is used by the ECS Agent to make calls on your behalf. If you enable logging for your FireLens container with the [`awslogs` Docker Driver](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html), you will need permissions for CloudWatch. You also need to give it S3 permissions if you are pulling an external Fluent Bit or Fluentd configuration file from S3. See the the [FireLens documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html) for more. |
| 31 | + |
| 32 | +Here is an example inline policy with S3 access for FireLens: |
| 33 | + |
| 34 | +``` |
| 35 | +{ |
| 36 | + "Version": "2012-10-17", |
| 37 | + "Statement": [ |
| 38 | + { |
| 39 | + "Effect": "Allow", |
| 40 | + "Action": [ |
| 41 | + "s3:GetObject" |
| 42 | + ], |
| 43 | + "Resource": [ |
| 44 | + "arn:aws:s3:::examplebucket/folder_name/config_file_name" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "Effect": "Allow", |
| 49 | + "Action": [ |
| 50 | + "s3:GetBucketLocation" |
| 51 | + ], |
| 52 | + "Resource": [ |
| 53 | + "arn:aws:s3:::examplebucket" |
| 54 | + ] |
| 55 | + } |
| 56 | + ] |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### Using the Examples |
| 61 | + |
| 62 | +You must update each Task Definition to reflect your own needs. Replace the IAM roles with your own roles. Update the log configuration with the values that you desire. And replace the app image with your own application image. |
| 63 | + |
| 64 | +Additionally, several of these examples use a custom Fluent Bit/Fluentd configuration file in S3. You must upload it to your own bucket, and change the S3 ARN in the example Task Definition. |
| 65 | + |
| 66 | +If you are using ECS on Fargate, then pulling a config file from S3 is not currently supported. Instead, you must create a custom Docker image with the config file. |
| 67 | + |
| 68 | +Dockerfile to add a custom configs: |
| 69 | +``` |
| 70 | +FROM amazon/aws-for-fluent-bit:latest |
| 71 | +ADD extra.conf /extra.conf |
| 72 | +``` |
| 73 | + |
| 74 | +Then update the `firelensConfiguration` `options` in the Task Definition to the following: |
| 75 | +``` |
| 76 | +"options": { |
| 77 | + "config-file-type": "file", |
| 78 | + "config-file-value": "/extra.conf" |
| 79 | +} |
| 80 | +``` |
| 81 | + |
5 | 82 | ## License Summary
|
6 | 83 |
|
7 | 84 | This sample code is made available under the MIT-0 license. See the LICENSE file.
|
0 commit comments