Install and configure AWS CloudWatch Logs Agent and deploy it's configurations automatically.
- Amazon Linux
- CentOS 7.x/RHEL 7.x
- Ubuntu 14.04, 16.04
- Chef 12.11+
None.
See attributes/default.rb
for the current default values as the listing below may not be current:
node['cwlogs']['region']
- Sets the AWS region in which the instance is located to run AWS CloudWatch Logs Agent. Defaultus-east-1
.node['cwlogs']['setup_home']
- Sets the location to install the AWS CloudWatch Logs Agent installer. Default/opt/aws/cloudwatch
.node['cwlogs']['agent_home']
- Sets the location or home (AGENT_HOME) for the AWS CloudWatch Logs Agent to store its configuration files. Default/var/awslogs
.
Checks if all necessary requirements are met, and afterwards will call install
and configure
recipes.
Installs AWS CloudWatch Logs Agent.
Prepares and configures all files required by AWS CloudWatch Logs.
Add this cookbook to your base recipe:
cookbook 'cloudwatch-logs', '~> 1.0.0'
You need to configure the following node attributes via an environment
or role
:
default_attributes(
'cwlogs' => {
'region' => 'your_aws_region',
'log' => {
'syslog' => {
'datetime_format' => '%b %d %H:%M:%S',
'file' => '/var/log/syslog',
'buffer_duration' => '5000',
'log_stream_name' => '{instance_id}',
'initial_position' => 'start_of_file',
'log_group_name' => '/var/log/syslog'
}
}
}
)
Or you can also configure by declaring it in another cookbook at a higher precedence level:
default['cwlogs']['region'] = 'your_aws_region'
default['cwlogs']['log']['syslog'] = {
'datetime_format' => '%b %d %H:%M:%S',
'file' => '/var/log/syslog',
'buffer_duration' => '5000',
'log_stream_name' => '{instance_id}',
'initial_position' => 'start_of_file',
'log_group_name' => '/var/log/syslog'
}
Note: This cookbook makes no provision for using AWS credentials stored on the instance. We assume you are following best practices and using an AWS IAM Role assigned to the instance.
Once you defined the attributes, you will need to reference cwlogs
resource in your recipe:
include_recipe 'cloudwatch-logs'
cwlogs 'syslog' do
log node['cwlogs']['log']['syslog']
end
cwlogs 'messages' do
log node['cwlogs']['log']['messages']
end
This will create unique configuration files in AWS CloudWatch Logs that will be stored in the ${AGENT_HOME}/etc/config
directory.
Remember: You can configure as many logs as you need with the log
attribute.
The example attributes used previously will generate the AWS CloudWatch Logs configuration below:
[syslog]
datetime_format = %b %d %H:%M:%S
file = /var/log/syslog
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = /var/log/syslog
For more deployment details about AWS CloudWatch Logs, please visit the AWS CloudWatch Logs Documentation.
The cwlogs resource is what the config recipe calls under the hood to setup the log configuration files.
- add
- remove
name
- Name of the log configuration file.log
- Log file setup details. A hash key/value pair following the AWS CloudWatch Logs Agent Reference format.
See CHANGELOG.md
for more details.
See LICENSE
for more details.
Amazon Web Services and AWS are trademarks of Amazon.com, Inc. or its affiliates in the United States and/or other countries.