Automating Deployments to On-Premises Servers with CodeDeploy Agent.

Automating Deployments to On-Premises Servers with CodeDeploy Agent.

Introduction.

Automating deployments to on-premises servers has become a crucial step in achieving consistent, reliable, and scalable software delivery in hybrid infrastructure environments. AWS CodeDeploy, a fully managed deployment service by Amazon Web Services, extends its capabilities beyond the cloud to support deployments directly to on-premises servers.

By installing the CodeDeploy agent on physical or virtual servers in your private data center, you can integrate these systems into your CI/CD pipeline, ensuring uniform software delivery practices across your entire fleet. This approach reduces manual errors, accelerates release cycles, and allows centralized control of application updates.

The CodeDeploy agent communicates securely with AWS services over HTTPS, ensuring that deployment instructions are received and executed properly. To utilize this functionality, servers must be registered with CodeDeploy and associated with appropriate IAM permissions and tag-based groupings.

Once set up, you can create deployment applications and groups targeting specific machines using custom tags. Deployment packages, often stored in Amazon S3 or GitHub, contain application code and an appspec.yml file defining the deployment lifecycle, including pre- and post-deployment hooks. These scripts handle tasks such as stopping services, backing up files, or starting applications after installation.

CodeDeploy supports various deployment configurations, such as “AllAtOnce” or “OneAtATime,” allowing fine-grained control over rollout strategy. With this setup, organizations can unify their deployment processes regardless of the server’s location, bringing cloud-like automation to on-prem systems. It also allows for easy rollback in case of failures, enhancing reliability and uptime.

Logging and status monitoring features help in auditing deployments and debugging issues efficiently. Overall, CodeDeploy’s support for on-premises instances provides a bridge between modern DevOps workflows and traditional infrastructure, allowing businesses to modernize at their own pace. Whether you’re maintaining legacy applications or modernizing existing infrastructure, CodeDeploy brings automation, repeatability, and consistency to your deployment pipeline.

It requires minimal changes to your existing systems and can be tailored to a wide range of operating systems and environments. The setup involves installing the CodeDeploy agent, registering the instance with AWS, configuring IAM roles, and defining deployment settings.

Once configured, deployments can be triggered via AWS CLI, SDKs, or CI/CD platforms like Jenkins or GitHub Actions. This strategy not only streamlines operations but also helps teams focus more on development and innovation, rather than spending time on manual deployments.

CodeDeploy enables true hybrid deployment capabilities, offering the benefits of cloud deployment automation for both cloud-based and on-premises infrastructure. This results in faster releases, reduced risk, and improved software quality across the organization.

1. Prerequisites

  • An AWS account
  • On-premises Linux or Windows servers
  • Access to install software and open outbound HTTPS traffic (for communicating with AWS)
  • An IAM user or role to manage CodeDeploy
  • AWS CLI installed and configured

2. Install CodeDeploy Agent on On-Premises Server

On Amazon Linux / RHEL / CentOS:

sudo yum update
sudo yum install ruby wget
cd /home/ec2-user
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start

Replace the region URL as needed (e.g., use us-west-2, etc.)

On Ubuntu/Debian:

sudo apt update
sudo apt install ruby wget
cd /home/ubuntu
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent start

3. Register On-Premises Server with CodeDeploy

Create an IAM user or role with the AWSCodeDeployFullAccess (or fine-tuned) policy.

Steps:

  1. Generate on-premises instance tags (e.g., Name=WebServer)
  2. Register the instance with CodeDeploy:
aws deploy register-on-premises-instance \
  --instance-name MyOnPremInstance \
  --iam-user-arn arn:aws:iam::123456789012:user/CodeDeployUser
  1. Attach the instance to tags:
aws deploy add-tags-to-on-premises-instances \
  --instance-names MyOnPremInstance \
  --tags Key=Name,Value=WebServer

Install the CodeDeploy agent credentials on the server:

aws deploy install --override-config

Start the agent and verify:

sudo service codedeploy-agent start
sudo service codedeploy-agent status

4. Setup CodeDeploy Application and Deployment Group

You can do this in the AWS Console or with CLI:

Create an application:

aws deploy create-application --application-name MyOnPremApp --compute-platform Server

Create a deployment group:

aws deploy create-deployment-group \
  --application-name MyOnPremApp \
  --deployment-group-name MyOnPremDG \
  --deployment-config-name CodeDeployDefault.AllAtOnce \
  --on-premises-instance-tag-filters Key=Name,Value=WebServer,Type=KEY_AND_VALUE \
  --service-role-arn arn:aws:iam::123456789012:role/CodeDeployServiceRole

5. Prepare Your AppSpec and Deployment Package

Your application must include an appspec.yml file. Example:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/app
hooks:
  BeforeInstall:
    - location: scripts/before_install.sh
      timeout: 300
      runas: ubuntu
  AfterInstall:
    - location: scripts/after_install.sh
      timeout: 300
      runas: ubuntu

6. Push Deployment to S3 or GitHub

Deployments can be sourced from:

  • Amazon S3
  • GitHub
  • Bitbucket

Example: Upload to S3

aws s3 cp my-app.zip s3://my-deployments-bucket/my-app.zip

7. Create and Trigger Deployment

aws deploy create-deployment \
  --application-name MyOnPremApp \
  --deployment-group-name MyOnPremDG \
  --s3-location bucket=my-deployments-bucket,key=my-app.zip,bundleType=zip

8. Monitor Deployment

Use the AWS Console or CLI:

aws deploy get-deployment --deployment-id d-XXXXXXXXX

Tips & Security

  • Make sure the on-prem server can reach *.amazonaws.com on port 443
  • Rotate IAM credentials regularly
  • Use least-privilege IAM policies

Conclusion.

In conclusion, automating deployments to on-premises servers using the AWS CodeDeploy agent offers a powerful solution for bridging the gap between traditional infrastructure and modern DevOps practices. It enables organizations to standardize deployment workflows across both cloud and on-premises environments, ensuring consistency, repeatability, and control.

By leveraging features like lifecycle hooks, rollback mechanisms, and integration with CI/CD tools, teams can deliver applications faster and more reliably. The process of setting up CodeDeploy on on-prem servers though requiring some initial configuration with IAM, instance registration, and tagging pays off significantly by reducing manual intervention and deployment errors.

Moreover, the flexibility to customize deployment strategies and scripts allows for seamless adaptation to existing infrastructure and application requirements. Whether you are maintaining legacy systems, migrating workloads, or simply aiming to modernize your deployment processes, AWS CodeDeploy provides the tools to automate and scale efficiently.

Ultimately, adopting this approach improves software delivery quality, enhances operational stability, and empowers development teams to focus more on innovation and less on deployment logistics.

Tags: No tags

Comments are closed.