Connect AWS Instance as Jenkins Slave Node

Sachin Mamoru
4 min readJul 7, 2023
Image Source

Introduction

Jenkins is a popular open-source automation server that allows continuous integration and delivery of software projects. One of its powerful features is the ability to distribute workloads across multiple machines, known as Jenkins slave nodes. In this article, we will guide you through the process of connecting an AWS (Amazon Web Services) instance as a Jenkins slave node, allowing you to scale your build and deployment processes.

Step 1: Set Up an AWS Instance

Image by Author
  1. Log in to your AWS Management Console and navigate to the EC2 service.
  2. Click on “Launch Instance” and select an appropriate Amazon Machine Image (AMI) based on your project requirements.
  3. Configure the instance settings, such as instance type, VPC, security groups, and storage. Ensure that you have SSH access enabled for the instance.
  4. Launch the instance and securely store the generated key pair.

Step 2: Install Java and Jenkins on the AWS Instance

Image by Author
  1. SSH into the AWS instance using the generated key pair.
  2. Update the package manager by running the command: sudo apt-get update.
  3. Install Java Development Kit (JDK) by executing the command: sudo apt-get install default-jdk.
  4. Verify the Java installation by running: java -version.
  5. Install Jenkins by following the official Jenkins installation guide for your operating system. Typically, it involves adding the Jenkins repository and installing the Jenkins package using the package manager.

Step 3: Configure Security Groups and Firewall Settings

Image by Author
  1. Go to the AWS Management Console and navigate to the EC2 service.
  2. Select the security group associated with your AWS instance.
  3. Add an inbound rule to allow TCP traffic on the Jenkins default port (usually port 8080) from your Jenkins master node’s IP address or security group.
  4. Save the security group settings.

Step 4: Configure Jenkins Master Node

  1. Open your Jenkins web interface by accessing http://<JENKINS_SERVER_IP>:8080 in a web browser.
  2. Install the necessary plugins for managing slave nodes. Go to “Manage Jenkins” > “Manage Plugins” > “Available” tab, and search for plugins like “SSH Agent” and “SSH Slaves.”
  3. Install and restart Jenkins after plugin installation.

Step 5: Configure Jenkins Slave Node

Image Source
  1. On the Jenkins web interface, go to “Manage Jenkins” > “Manage Nodes and Clouds” > “New Node.”
  2. Provide a name for the slave node and select “Permanent Agent.”
  3. Configure the following settings:
  • Number of Executors: The maximum number of concurrent builds the slave node can handle.
  • Remote root directory: The workspace directory on the slave node.
  • Labels: Assign labels to categorize your slave nodes (optional).
  • Launch method: Select “Launch agents via SSH.”
  • Host: Enter the public DNS or IP address of your AWS instance.
  • Credentials: Click on “Add” and provide the SSH private key associated with your AWS instance.
  • Host Key Verification Strategy: Select “Manually trusted key verification strategy.”

4. Save the configuration.

Step 6: Launch Jenkins Slave Node

  1. On the Jenkins web interface, navigate to the “Nodes” page.
  2. Find the newly created slave node and click on “Launch agent” from the sidebar.
  3. Jenkins will initiate a connection with the AWS instance using SSH and start the slave node.
  4. Once the connection is established, the slave node will appear as online on the “Nodes” page.

Conclusion

By connecting an AWS instance as a Jenkins slave node, you can efficiently distribute build and deployment workloads, allowing for better scalability and faster software delivery. This article provided a step-by-step guide to set up an AWS instance, install Java and Jenkins, configure security groups, and connect the instance as a Jenkins slave node. With this configuration in place, you can leverage the power of AWS and Jenkins to optimize your CI/CD processes.

Thank you for reading and please share your own tips and ideas in the comments below 😊

--

--