Getting Ubuntu cloud-init to work in an Amazon (AWS) VPC

Ubuntu's cloud-init is a mechanism which can be used to provision a new instance upon initial boot. I imagine cloud-init can be used in many environments, but I'll focus on its use in Amazon Web Services (AWS).

You can invoke cloud-init in at least a couple ways :

- shell, with a lead line of #!/bin/sh
- cloud-init, with a lead line of #cloud-config

There are several examples of provisioning with cloud-init, including a Drupal example.

However, I ran into a problem when running the examples in an AWS virtual private cloud (VPC). I could get simple commands like 'echo' to run, but was having trouble with apt-get (aptitude). However, outside of a VPC (in 'classic' EC2-land), apt-get ran properly in cloud-init.

The problem with apt-get seems to be that in classic EC2-land, Ubuntu images reference an apt repository which is in a 10.* subnet. In a VPC, unless you've set up your own apt repository, your new EC2 image won't see that apt repository. This issue is discussed in a Launchpad bug.

The easiest workaround seems to be to add an 'apt_mirror:' entry right after the initial line of '#cloud-config' :


If you're building a lot of instances regularly, you might want to build up a local repository to save on bandwidth charges, but the above should be a quick workaround.

NOTE : This post has a follow-up.