Skip to content

Prepare the EC2 server

Install the CodeDeploy agent and confirm the server is ready to receive releases.

About 15 min · Verified 8 October 2026

0 of 4 steps done0%

CodeDeploy does not log in to your server. Instead a small agent program runs on it, asks CodeDeploy "is there a deployment for me?", downloads the bundle and runs your hook scripts. You install the agent once.

Run everything in this chapter on the EC2 instance: EC2Instancesshortlink-apiConnectSession Manager.

Install the agent#

Install the prerequisites#

On the EC2 instanceMake sure wget is present
sudo apt-get update
sudo apt-get install -y wget

Download and run the installer for your Region#

The installer is served from a regional S3 bucket. The URL contains your Region twice.

On the EC2 instanceInstall the CodeDeploy agent
cd /tmp
wget -O codedeploy-install https://aws-codedeploy-ap-south-1.s3.ap-south-1.amazonaws.com/latestv2/install
chmod +x ./codedeploy-install
sudo ./codedeploy-install auto
The installer complains about Ruby

Older agent versions needed Ruby. The latestv2 installer normally does not. If you see ruby: command not found, install it and run the installer again:

On the EC2 instanceInstall Ruby, then retry
sudo apt-get install -y ruby-full
sudo ./codedeploy-install auto

Check that the agent is running#

On the EC2 instanceAgent status
sudo systemctl is-active codedeploy-agent
You should see
active

Check what the hooks rely on#

The service and the env file exist#

On the EC2 instancePre-flight checks for the hook scripts
systemctl is-enabled shortlink-api
sudo -u ubuntu test -r /etc/shortlink/shortlink.env && echo "env file readable by ubuntu"
test -d /opt/shortlink && echo "/opt/shortlink exists"
command -v node
You should see
enabled, then env file readable by ubuntu, /opt/shortlink exists, and /usr/bin/node.

If any of these fail, go back to the Install and start the API chapter in guide 1. The very first release would otherwise fail in BeforeInstall.

Next: create the CodeDeploy application.

Found a mistake? Edit this page on GitHub.