Create a custom log parser for Amazon ECS using a Firelens log router
Created by Varun Sharma (AWS)
Summary
Firelens is a log router for Amazon Elastic Container Service (Amazon ECS) and AWS Fargate. You can use Firelens to route container logs from Amazon ECS to Amazon CloudWatch and other destinations (for example, Splunk
By choosing to parse logs at the source level, you can analyze your logging data and perform queries to more efficiently and effectively respond to operational issues. Because different applications have different logging patterns, you need to use a custom parser that structures the logs and makes searching easier at your end destination.
This pattern uses a Firelens log router with a custom parser to push logs to CloudWatch from a sample Spring Boot application running on Amazon ECS. You can then use Amazon CloudWatch Logs Insights to filter the logs based on custom fields that are generated by the custom parser.
Prerequisites and limitations
Prerequisites
An active Amazon Web Services (AWS) account.
AWS Command Line Interface (AWS CLI), installed and configured on your local machine.
Docker, installed and configured on your local machine.
An existing Spring Boot-based containerized application on Amazon Elastic Container Registry (Amazon ECR).
Architecture
Technology stack
CloudWatch
Amazon ECR
Amazon ECS
Fargate
Docker
Fluent Bit
Tools
Amazon ECR – Amazon Elastic Container Registry (Amazon ECR) is an AWS managed container image registry service that is secure, scalable, and reliable.
Amazon ECS – Amazon Elastic Container Service (Amazon ECS) is a highly scalable, fast container management service that makes it easy to run, stop, and manage containers on a cluster.
AWS Identity and Access Management (IAM) – IAM is a web service for securely controlling access to AWS services.
AWS CLI – AWS Command Line Interface (AWS CLI) is an open-source tool that enables you to interact with AWS services using commands in your command-line shell.
Docker
– Docker is an open platform for developing, shipping, and running applications.
Code
The following files are attached to this pattern:
customFluentBit.zip
– Contains the files to add the custom parsing and configurations.firelens_policy.json
– Contains the policy document to create an IAM policy.Task.json
– Contains a sample task definition for Amazon ECS.
Epics
Task | Description | Skills required |
---|---|---|
Create an Amazon ECR repository. | Sign in to the AWS Management Console, open the Amazon ECR console, and create a repository called For more information about this, see Creating a repository in the Amazon ECR documentation. | Systems administrator, Developer |
Unzip the customFluentBit.zip package. |
| |
Create the custom Docker image. |
For more information about this, see Pushing a Docker image in the Amazon ECR documentation. | Systems administrator, Developer |
Task | Description | Skills required |
---|---|---|
Create an Amazon ECS cluster. | Create an Amazon ECS cluster by following the instructions from the Networking only template section of Creating a cluster in the Amazon ECS documentation. NoteMake sure that you choose Create VPC to create a new virtual private cloud (VPC) for your Amazon ECS cluster. | Systems administrator, Developer |
Task | Description | Skills required |
---|---|---|
Set up the Amazon ECS task execution IAM role. | Create an Amazon ECS task execution IAM role by using the NoteMake sure that you record the IAM role’s Amazon Resource Name (ARN). | Systems administrator, Developer |
Attach the IAM policy to the Amazon ECS task execution IAM role. |
| Systems administrator, Developer |
Set up the Amazon ECS task definition. |
For more information about this, see Creating a task definition in the Amazon ECS documentation. | Systems administrator, Developer |
Task | Description | Skills required |
---|---|---|
Run the Amazon ECS task. | On the Amazon ECS console, choose Clusters, choose the cluster that you created earlier, and then run the standalone task. For more information about this, see Run a standalone task in the Amazon ECS documentation. | Systems administrator, Developer |
Task | Description | Skills required |
---|---|---|
Verify the logs. |
| Systems administrator, Developer |
Related resources
Attachments
To access additional content that is associated with this document, unzip the following file: attachment.zip