Set up an AWS VM build infrastructure
Set up a CI build infrastructure using AWS VMs.
This feature is planned to be deprecated at the end of January 2027 as we transition to our Unified Runner (Delegate 3.0), which merges the runner and delegate into a single component and introduces additional capabilities and improvements.
The current implementation will continue to be fully supported while the Unified Runner is introduced, and both will be available side-by-side during the transition period. We will share detailed guidance well ahead of the change, and customers will have sufficient time, tooling, and support to plan and complete their migration before the deprecation takes effect.
If you have any questions, please contact your account representative or Harness Support.
This topic describes how to use AWS VMs as Harness CI build infrastructure. To do this, you will create an Ubuntu VM and install a Harness Delegate and Drone VM Runner on it. The runner creates VMs dynamically in response to CI build requests. You can also configure the runner to hibernate AWS Linux and Windows VMs when they aren't needed.
This is one of several CI build infrastructure options. For example, you can also set up a Kubernetes cluster build infrastructure.
The following diagram illustrates a CI build farm using AWS VMs. The Harness Delegate communicates directly with your Harness instance. The VM runner maintains a pool of VMs for running builds. When the delegate receives a build request, it forwards the request to the runner, which runs the build on an available VM.
Prepare the AWS EC2 instance
These are the requirements to configure the AWS EC2 instance. This instance is the primary VM where you will host your Harness Delegate and runner.
Configure authentication for the EC2 instance
The recommended authentication method is an IAM role on the VM instance, but using IAM user and access key and secret (AWS secret) is also supported. It is best practice to use an IAM role over an access key and secret for security reasons.
Create or select an IAM role for the primary VM instance. This IAM role must have CRUD permissions on EC2. This role provides the runner with temporary security credentials to create VMs and manage the build pool. For details, go to the Amazon documentation on AmazonEC2FullAccess Managed policy.
If you plan to run Windows builds, You must add the AdministratorAccess policy to the IAM role associated with the access key and access secret.
If you haven't done so already, create an access key and secret for the IAM role.
Launch the EC2 instance
In the AWS EC2 Console, launch a VM instance that will host your Harness Delegate and runner. This instance must use an Ubuntu AMI that is
t2.largeor greater.The primary VM must be Ubuntu. The build VMs (in your VM pool) can be Ubuntu, AWS Linux, or Windows Server 2019 or higher. All machine images must have Docker installed.
Attach a key pair to your EC2 instance. Create a key pair if you don't already have one.
You don't need to enable Allow HTTP/HTTPS traffic.
Configure ports and security group settings
Create a Security Group in the EC2 console. You need the Security Group ID to configure the runner. For information on creating Security Groups, go to the AWS documentation on authorizing inbound traffic for your Linux instances.
In the Security Group's Inbound Rules, allow ingress on port 9079. This is required for security groups within the VPC.
In the EC2 console, go to your EC2 VM instance's Inbound Rules, and allow ingress on port 22.
If you want to run Windows builds and be able to RDP into your build VMs, you must also allow ingress on port 3389.
Allow ingress rules for port 3000 as well.
Outbound access to githubusercontent.com over 443, which is allowed by default in a typical security group.
Outbound access to googleapis.com over 443 to ship the task logs. Can be avoided by using the account setting "Account Settings"->"Default Settings"->"Continuous Integration->"Upload Logs via Harness".
Set up VPC firewall rules for the build instances on EC2.
Install Docker and attach IAM role
Attach the IAM role to the EC2 VM. For instructions, go to the AWS documentation on attaching an IAM role to an instance.
Use a custom Windows AMI
If you plan to use a custom Windows AMI in your AWS VM build farm, you must delete state.run-once from your custom AMI.
In Windows, sysprep checks if state.run-once exists at C:\ProgramData\Amazon\EC2Launch\state.run-once. If the file exists, sysprep doesn't run post-boot scripts (such as cloudinit, which is required for Harness VM build infrastructure). Therefore, you must delete this file from your AMI so it doesn't block the VM init script.
If you get an error about an unrecognized refreshenv command, you might need to install Chocolatey and add it to $profile to enable the refreshenv command.
Environment Variables
Optionally set the following environment variables:
HEALTH_CHECK_TIMEOUT
Integer. Set a time out (in minutes) for the health check. Works only for Mac and Linux. For example, HEALTH_CHECK_TIMEOUT=6 would set a 6 minute timeout.
3
HEALTH_CHECK_WINDOWS_TIMEOUT
Integer. Set a time out (in minutes) for the health check. Works only for Windows. For example, HEALTH_CHECK_WINDOWS_TIMEOUT=6 would set a 6 minute timeout.
5
Configure the Drone pool on the AWS VM
The pool.yml file defines the VM spec and pool size for the VM instances used to run the pipeline. A pool is a group of instantiated VMs that are immediately available to run CI pipelines. You can configure multiple pools in pool.yml, such as a Windows VM pool and a Linux VM pool. To avoid unnecessary costs, you can configure pool.yml to hibernate VMs when not in use.
Create a
/runnerfolder on your delegate VM andcdinto it:In the
/runnerfolder, create apool.ymlfile.Modify
pool.ymlas described in the following example and the Pool settings reference.
Example pool.yml
The following pool.yml example defines both an Ubuntu pool and a Windows pool.
Pool settings reference
You can configure the following settings in your pool.yml file. You can also learn more in the Drone documentation for the Pool File and Amazon drivers.
name
String
name: windows_pool
Unique identifier of the pool. You will need to specify this pool name in Harness when you set up the CI stage build infrastructure.
pool
Integer
pool: 1
Warm pool size number. Denotes the number of VMs in ready state to be used by the runner.
limit
Integer
limit: 3
Maximum number of VMs the runner can create at any time. pool indicates the number of warm VMs, and the runner can create more VMs on demand up to the limit.
For example, assume pool: 3 and limit: 10. If the runner gets a request for 5 VMs, it immediately provisions the 3 warm VMs (from pool) and provisions 2 more, which are not warm and take time to initialize.
platform
Key-value pairs, strings
Go to platform example.
Specify VM platform operating system (os: linux or os: windows). arch and variant are optional. os_name: amazon-linux is required for AL2 AMIs. The default configuration is os: linux and arch: amd64.
spec
Key-value pairs, various
Go to Example pool.yml and the examples in the following rows.
Configure settings for the build VMs and AWS instance. Contains a series of individual and mapped settings, including account, tags, ami, size, hibernate, iam_profile_arn, network, user_data, user_data_path, and disk. Details about these settings are provided below.
account
Key-value pairs, strings
Go to account example.
AWS account configuration, including region and access key authentication.
region(required): AWS region. To minimize latency, use the same region as the delegate VM.availability_zone(optional): AWS region availability zone. To minimize latency, use the same availability zone as the delegate VM.access_key_id: The AWS access key for authentication. If using an IAM role, this is the access key associated with the IAM role.access_key_secret: The secret associated with the specifiedaccess_key_id.key_pair_name: The key pair name specified when you set up the EC2 instance. Don't include.pem.
ami
String
ami: ami-092f63f22143765a3
The AMI ID. You can use the same AMI as your EC2 instance or search for AMIs in your Availability Zone for supported models (Ubuntu, AWS Linux, Windows 2019+). AMI IDs differ by Availability Zone.
size
String
size: t3.large
The AMI size, such as t2.nano, t2.micro, m4.large, and so on. Make sure the size is large enough to handle your builds.
hibernate
Boolean
hibernate: true
When set to true (which is the default), VMs hibernate after startup. When false, VMs are always in a running state. This option is supported for AWS Linux and Windows VMs. Hibernation for Ubuntu VMs is not currently supported. For more information, go to the AWS documentation on hibernating on-demand Linux instances.
iam_profile_arn
String
iam_profile_arn: arn:aws:iam::XXXX:instance-profile/XXX
If using IAM roles, this is the instance profile ARN of the IAM role to apply to the build instances.
network
Key-value pairs, various
Go to network example.
AWS network information, including security groups. For more information on these attributes, go to the AWS documentation on creating security groups.
security_groups: List of security group IDs as strings.vpc: If using VPC, this is the VPC ID as an integer.vpc_security_groups: If using VPC, this is a list of VPC security group IDs as strings.private_ip: Boolean.subnet_id: The subnet ID as a string.
user_data or user_data_path
Key-value pairs, strings
Go to user data example.
Define custom user data to apply to the instance. Provide cloud-init data in either user_data_path or user_data if you need custom configuration.
disk
Key-value pairs, various
Go to disk example.
Optional AWS block information.
size: Integer, size in GB.type:gp2,io1, orstandard.iops: Iftype: io1, theniops: iops.kms_key_id: Your AWS KMS Key ID
platform example
account example
tags example
network example
user data example
Provide cloud-init data in either user_data_path or user_data if you need custom configuration. Refer to the user data examples for supported runtime environments.
Below is a sample pool.yml for GCP with user_data configuration:
disk example
The tags property exemplified above follows a key/value pair format. This will add tags to the disk/volume directly.
Start the runner
SSH into your EC2 instance and run the following command to start the runner:
This command mounts the volume to the Docker runner container and provides access to pool.yml, which is used to authenticate with AWS and pass the spec for the pool VMs to the container. It also exposes port 3000.
You might need to modify the command to use sudo and specify the runner directory path, for example:
Install the delegate
Install a Harness Docker Delegate on your AWS EC2 instance.
In Harness, go to Account Settings, select Account Resources, and then select Delegates.
You can also create delegates at the project scope. In your Harness project, select Project Settings, and then select Delegates.
Select New Delegate or Install Delegate.
Select Docker.
Enter a Delegate Name.
Copy the delegate install command and paste it in a text editor.
To the first line, add
--network host, and, if required,sudo. For example:SSH into your EC2 instance and run the delegate install command.
For more information about delegates and delegate installation, go to Delegate installation overview.
Verify connectivity
Verify that the delegate and runner containers are running correctly. You might need to wait a few minutes for both processes to start. You can run the following commands to check the process status:
In the Harness UI, verify that the delegate appears in the delegates list. It might take two or three minutes for the Delegates list to update. Make sure the Connectivity Status is Connected. If the Connectivity Status is Not Connected, make sure the Docker host can connect to
https://app.harness.io.
The delegate and runner are now installed, registered, and connected.
Specify build infrastructure
Configure your pipeline's Build (CI) stage to use your AWS VMs as build infrastructure.
In Harness, go to the CI pipeline that you want to use the AWS VM build infrastructure.
Select the Build stage, and then select the Infrastructure tab.
Select VMs.
Enter the Pool Name from your pool.yml.
Save the pipeline.
Delegate selectors with self-managed VM build infrastructures
Although you must install a delegate to use a self-managed VM build infrastructure, you can choose to use a different delegate for executions and cleanups in individual pipelines or stages. To do this, use pipeline-level delegate selectors or stage-level delegate selectors.
Delegate selections take precedence in the following order:
Stage
Pipeline
Platform (build machine delegate)
This means that if delegate selectors are present at the pipeline and stage levels, then these selections override the platform delegate, which is the delegate that you installed on your primary VM with the runner. If a stage has a stage-level delegate selector, then it uses that delegate. Stages that don't have stage-level delegate selectors use the pipeline-level selector, if present, or the platform delegate.
For example, assume you have a pipeline with three stages called alpha, beta, and gamma. If you specify a stage-level delegate selector on alpha and you don't specify a pipeline-level delegate selector, then alpha uses the stage-level delegate, and the other stages (beta and gamma) use the platform delegate.
AWS Fargate Limitations
If you are running builds on AWS Fargate, please be aware of the following limitations.
Docker delegate on AWS ECS Fargate backed instance
When operating ECS delegates on AWS Fargate, it's critical to note that AWS Fargate will terminate the delegate if the tasks running on the delegate exceed the infrastructure's specified limits. This is a limitation inherent in using infrastructure not owned by the customer. Harness Delegate cannot circumvent this restriction. However, ECS delegates operating on an EC2 instance do not have this issue. To avoid this limitation, consider using Kubernetes delegates where the infrastructure and associated YAML definitions address these issues.
Docker in Docker does not work with AWS Fargate
AWS Fargate doesn't support the use of privileged containers. Privileged mode is required for DinD, thus, you cannot use DinD with AWS Fargate.
AWS Fargate does not support IAM roles
Amazon requires the Amazon EKS Pod execution role to run pods on the AWS Fargate infrastructure. For more information, go to Amazon EKS Pod execution IAM role in the AWS documentation.
If you deploy pods to Fargate nodes in an EKS cluster, and your nodes needs IAM credentials, you must configure IRSA in your AWS EKS configuration (and then select the Use IRSA option for your connector credentials in Harness). This is due to Fargate limitations.
Troubleshoot AWS VM build infrastructure
Go to the CI Knowledge Base for a broader list of frequently asked questions and answers.
Last updated
Was this helpful?