11.6.1.2. Using EC2 instances as part of your build farm
Creating a new EC2 instance is as simple as choosing the base image you want to use. You will just
need to provide some details about the instance, such as its size and capacity, and the private key you
want to use to access the machine. Amazon will then create a new running virtual machine based on this
image. Once you have set it up, an EC2 instance is essentially a machine like any other, and it is easy and
convenient to set up permanent or semipermanent EC2 machines as part of your build infrastructure.
You may even opt to use an EC2 image as your master server.
Setting up an existing EC2 instance as a Jenkins slave is little different to setting up any other remote
slave. If you are setting up a Unix or Linux EC2 slave, you will need to refer to the private key file
(see Figure 11.18, “Configuring an Amazon EC2 slave”) that you used to create the EC2 instance on
the AWS Management console. Depending on the flavor of Linux you are using, you may also need
to provide a username. Most distributions connect as root, but some, such as Ubuntu, need a different
user name.
Figure 11.18. Configuring an Amazon EC2 slave
11.6.1.3. Using dynamic instances
The second approach involves creating new Amazon EC2 machines dynamically, as they are required.
Setting up dedicated instances is not difficult, but it does not scale well. A better approach is to let
Jenkins create new instances as require. To do this, you will need to install the Jenkins Amazon EC2
plugin. This plugin lets your Jenkins instance start slaves on the EC2 cloud on demand, and then kill
them off when they are no longer needed. The plugin works both with Amazon EC2, and the Ubuntu
Enterprise Cloud. We will be focusing on Amazon EC2 here. Note that at the time of writing the Amazon
EC2 Plugin only supported managing Unix EC2 images.
Once you have installed the plugin and restarted Jenkins, go to the main Jenkins configuration screen and
click on Add a New Cloud (see Figure 11.19, “Configuring an Amazon EC2 slave”). Choose Amazon
EC2. You will need to provide your Amazon Access Key ID and Secret Access Key so that Jenkins
can communicate with your Amazon EC2 account. You can access these in the Key Pairs screen of
your EC2 dashboard.