Ingest logs from Amazon ECS using AWS firelens
This guide provides step-by-step instructions to integrate Amazon Elastic Container Service (ECS) with OpenObserve for log ingestion using AWS FireLens.
Introduction
To send logs from ECS tasks (Fargate or EC2, Linux) to OpenObserve, use AWS FireLens with a Fluent Bit sidecar. FireLens routes container logs in ECS tasks to Fluent Bit, which then forwards them to OpenObserve.
We recommend Fluent Bit over Fluentd due to its lower resource usage. For existing tasks, update the task definition to include the Fluent Bit sidecar.
A sidecar is just an extra container that runs in the same ECS task (or Kubernetes pod) as your main application container, but it provides a supporting service rather than running the main app.
Steps to Integrate
Prerequisites
- An OpenObserve Cloud account or OpenObserve self hosted setup.
- A running ECS cluster that supports fargate. If you don't already have one, create one by following the documentation.
We will run our tasks using fargate for this demonstration.
Get OpenObserve Credentials
You can find the config details under Data sources -> fluentbit
You can use the configuration details from this section in your task definition
Create ECS task definition
-
Create the following file and save it as "nginx_firelens_zo_task_def.json"
logDriver
in this case isawsfirelens
. All the logs for nginx container will be sent to fluentbit usingawsfirelens
.options
section has http output plugin configuration for fluentbit. Configure this section with the values you got from OpenObserve.
-
Register the task definition using the below command:
We will also need to provide network configuration when using networkMode asawsvpc
during service creation. Let's create a json file for that:
Note: Do not set
assignPublicIp
on line10
as ENABLED for real world scenarios. You do not want to access tasks directly. We are doing this now only for demonstration. You should always either front the services with a load balancer or AWSCloud Map
.
Create ECS service
Now let's create an ECS service
that will use this task definition.
Assuming the name of your cluster - ecs1_fargate_cluster1
run below command:
Verify result
-
If all goes well, you should see a running service on ECS console:
-
Now click on the tasks tab. You should see a task running as part of the service:
-
Now click on the task:
-
You should see the
Public IP
for the task. Clickopen address
. You should see the following page: -
Now head on the OpenObserve / OpenObserve Cloud and see the logs flowing in there.
Conclusion
AWS firelens provides an easy way to send ECS container logs to OpenObserve. We configured AWS firelens in few steps to send logs to OpenObserve / OpenObserve Cloud. to easily view and analyze logs.