Skip to content

Instantly share code, notes, and snippets.

@mvanholsteijn
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanholsteijn/1399ccd934fdc4fc91ac to your computer and use it in GitHub Desktop.
Save mvanholsteijn/1399ccd934fdc4fc91ac to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Installs and Configures the AWS cloudwatch agent, and sets the default log group name and region
#
#
# You need to add the following policy statement to the machine's IAM role.
#
# {
# "Effect": "Allow",
# "Action": [
# "logs:CreateLogGroup",
# "logs:CreateLogStream",
# "logs:PutLogEvents",
# "logs:DescribeLogStreams"
# ],
# "Resource": [
# "arn:aws:logs:*:*:*"
# ]
# }
#
LOG_GROUP=ecs-syslog-default
REGION=eu-west-1
function usage() {
echo "USAGE: $(basename $0) [-g log-group-name] [-r region]" >&2
echo " $@" >&2
}
while getopts ":g:r:" OPT; do
case $OPT in
g)
LOG_GROUP=$OPTARG;;
r)
REGION=$OPTARG;;
\?)
usage "Invalid option: -$OPTARG"
exit 1 ;;
esac
done
sudo yum install -y awslogs
sudo sed -i "s/^region[ \t]*=.*/region = $REGION/" /etc/awslogs/awscli.conf
sudo sed -i "s/^log_group_name[ \t]*=.*/log_group_name = $LOG_GROUP/" /etc/awslogs/awslogs.conf
sudo chkconfig awslogs on
sudo service awslogs start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment