Vagrant AWS

Two colleages brought my attention to a neat little tool called vagrant while i listened to their podcast. This basically lets us create small config files that specify and configure Virtual Machines. We can check-in these files in the repository and everyone can start up the same VM locally without all the configuration.


Using vagrant locally is pretty easy and the next step was to start up AWS instances with it. Thanks to Mitchell Hashimoto who did already implement a vagrant plugin for AWS vagrant-aws.

At first we add a new box to our local vagrant.
vagrant box add dummy aws/raw/master/

Next we configure our Vagrantfile.

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "dummy"

  config.vm.provider :aws do |aws, override|
      aws.access_key_id = <Access Key>
      aws.secret_access_key = <Access Secret>
      aws.keypair_name = <Keypair Name>
      aws.instance_type = "m1.small"
      aws.tags = {
              Name: <name your instance>

      aws.ami = "ami-35792c5c"

      override.ssh.username = <username>
      override.ssh.private_key_path = <path to private key>

Now call vagrant up --provider=aws (with --provider=aws vagrant always starts a new instance). We can suspend our instance with vagrant halt and start it up again with vagrant up (notice the missing provider options)
With ssh configured correctly we can now simply type vagrant ssh to connect to the server.

Storage Size

One last thing i stumbled upon. AWS Ec2 instances have an initial disc space of 8Gb. To increase the storage space we have to add the following to our Vagrantfile.

aws.block_device_mapping = [  
            'DeviceName' => "/dev/sda1",
            'VirtualName' => "root",
            'Ebs.VolumeSize' => 20,
            'Ebs.DeleteOnTermination' => true

This will increases the root partition to 20gb.
After we did boot the instance and connected via ssh, 1 last command is necessary.
sudo resize2fs /dev/xvda1

Thomas Sattlecker

Thomas Sattlecker

View Comments