David shows you how to
use CloudWatch to help
troubleshoot Auto Scaling
deployment failures


How do I use AWS CodeDeploy and Amazon CloudWatch to help me troubleshoot deployment failures when an Auto Scaling group terminates an instance?

First, create an IAM role and attach the CloudWatchLogsFullAccess managed policy, as well as any other permissions your use case requires.

Next, create a launch configuration (be sure to specify the IAM role you created on the previous step). On the Configure Details page, open the Advanced Details drop-down and add commands to the User data field that perform the following actions, in order:

  1. Install prerequisite software to run the CodeDeploy agent and the AWS CLI.
  2. Install the CloudWatch logs agent and specify a default log configuration.
  3. Download the CodeDeploy configuration file and update the CloudWatch log agent to use the new configuration file.
  4. Install the CodeDeploy host agent.

Here is an example of the way these commands might look:

yum -y update
yum install -y ruby
yum install -y aws-cli
cd /home/ec2-user
curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -O
chmod +x ./awslogs-agent-setup.py
./awslogs-agent-setup.py -n -r us-east-1 -c s3://aws-codedeploy-<region>/cloudwatch/awslogs.conf
service awslogs stop
wget https://s3.amazonaws.com/aws-codedeploy-<region>/cloudwatch/codedeploy_logs.conf .
cp codedeploy_logs.conf /var/awslogs/etc/config/codedeploy_logs.conf
service awslogs start
aws s3 cp s3://aws-codedeploy-<region>/latest/install . --region <region>
chmod +x ./install
./install auto

Last, create an Auto Scaling group that uses your newly created launch configuration and set Group size to 1; configure all other attributes to best meet your use case. Choose Save, and your instance will launch.

When your instance is in the running state, verify that the awslogs service is running by logging in to the instance using SSH and running the following command:

sudo service awslogs status

You can view your CodeDeploy logs in the CloudWatch console by choosing Logs. Any new instances in this Auto Scaling group will automatically install and start the awslogs agent at launch.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2017-02-10