A couple of months ago when I sat up my multicontainer docker environment on AWS Elastic Beanstalk I realized that I could only export my logs manually from the Elastic Beanstalk user interface. So I started looking into ways of sending my logs in real-time from my docker environment to some external service where I could archive and search them easily at a later point for statistics and debugging purposes.
After some googling, I found that docker has a gelf (Graylog Extended Log Format) log driver, so I ended up choosing AWS Elasticsearch as my logging service since it is easy to query in Elasticsearch and also to create graphs and visual output of your data in Kibana. I tried to just simply add a new section in my Dockerrun.aws.json file that changed the log driver of the docker container to gelf [reference].
However, this did not work as expected since the AWS ECS agent does not have the gelf log driver activated by default, it has to be activated before the agent starts. The only way I found to achieve this is by adding gelf log driver support to the AWS ECS agent through a custom Elastic Beanstalk extension and then restarting the AWS ECS process.
I set up my environment by adding the following two Elastic Beanstalk extensions to the root of my GitHub repository. The contents of the first file
.ebextensions/gelf.config goes as follows:
The contents of the second ebextension file
.ebextensions/restart-docker.config should be:
Once those two files are in place, gelf logging support should be activated in the AWS ECS agent on the next deploy, auto scale or environment rebuild on Elastic Beanstalk. Now it should be as easy as just adding a logstash container to the Dockerrun.aws.json file to run a logstash container in the multicontainer docker environment.
You can use any logstash docker image that you would like, however, if you would like to use the one that I have build listed in the Dockerrun.aws.json file above, you need to add two logstash configuration files in a .logstash folder in the root of your repository.
.logstash/logstash.conf, which corresponds to the
--path.config setting in logstash which is your pipeline configuration file and another file
.logstash/logstash.yml which is the logstash settings configuration file which is set with the
I hope that this helps someone out there that is looking into ways of how to send logs to AWS Elasticsearch from a multicontainer docker environment in AWS Elastic Beanstalk.