Logan walks you through
using launch configurations
to install the CodeDeploy agent

codedeploy-agent-launch-configuration-logan

How can I use launch configurations to automatically install the CodeDeploy agent on an EC2 instance running Amazon Linux?

Note: These instructions apply for EC2 instances running Amazon Linux. For instructions for instances running Ubuntu, see Install or reinstall the AWS CodeDeploy agent for Ubuntu Server.

When you create a launch configuration, you can use the User data field to add commands to execute when the instance starts.

If you're running an instance that is based on an Amazon Linux AMI, you can use the AWS CLI to automatically install the CodeDeploy agent on instances. To do this, create a launch configuration, but add code similar to the following to the User data field:

#!/bin/bash
yum -y update
yum install -y ruby
yum install -y aws-cli
cd /home/ec2-user
aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . --region us-east-1
chmod +x ./install
./install auto

If you prefer to use the Linux command wget instead, you could add code similar to the following to the User data field, which defines the variable REGION as an instance's Availability Zone, and then calls the variable to retrieve the CodeDeploy agent installation files from the geographically-closest Amazon S3 bucket:

#!/bin/bash -x
REGION=$(curl 169.254.169.254/latest/meta-data/placement/availability-zone/ | sed 's/[a-z]$//')
yum update -y
yum install ruby wget -y
cd /home/ec2-user
wget https://aws-codedeploy-$REGION.s3.amazonaws.com/latest/install
chmod +x ./install
./install auto


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