AWS CloudWatch Logs for ChefMay 21, 2017 · 7 min read
AWS CloudWatch Logs is great service, it allows you to monitor your log files in centralized way in a nearly real-time through AWS Console, and also allows you to search in logs for specific phrases, values, or patterns.
In order to help the deploy of CloudWatch Logs configurations, I started developing this cookbook when we at fluig Identity, chose AWS CloudWatch Logs as the solution for centralize all the logs that our applications generate (today is about 250GB per month).
Below I’m going to show you how the cookbook works and how you can use it in your Chef.
First add this cookbook to your base recipe to install the agent in all of your servers (you can use berks to download directly from Chef Supermarket):
You need to configure the following node attributes by an
role, so the recipe can configure the agent by your specific configuration. All attributes are described at CloudWatch Logs official documentation, so please take a visit to understand and adapt it to your need.
Note: If you don’t specify AWS credentials, the CloudWatch Logs Agent will attempt to use the AWS IAM Role assigned to the instance.
You can also opt to configure by declaring it in another cookbook at a higher precedence level.
Once you defined those attributes, you will need to reference
aws_cwlogs resource in one of your recipes, by doing:
This will create a unique log configuration file that will be stored in
etc/config directory of your CloudWatch Logs Agent.
If you have more that one
log attribute, each log referred will be created in its own configuration file. This avoid us to create invalid configurations in servers that don’t have the log specified.
For a complete documentation of the cookbook, please take a look at the project on GitHub.
Those attributes used before will generate the CloudWatch Logs configuration below.
Remember: You can configure as many logs as you need with the
Currently, this cookbook was develop and tested only in Ubuntu, but, of course, pull requests are always welcome. If you have any questions, please feel free to create a New Issue on the project.