Thomas James Just a geek.

Technology, Gadgetry, Photography and Software Development

Making Ubuntu apt faster on ec2


Note, this is based on experience in ap-southeast-2 only, using Ubuntu Cloud AMIs

I’ve found the performance of the default Ubuntu AWS region based apt mirror to vary greatly. Sometimes downloading a package will occur at 6+MB/s while other times it’ll be barely 1KB/s.

This can be a problem if you’re not pre-baking you’re AMIs and you hit the grace period for instance spin-up in an autoscale group with a health check. If you’re not careful you’ll have a cycle of spin-up->unhealthy->terminate, which could end up being quite costly.

The source of this would appear to be load on the mirrors. Thankfully canonical have provided a simple solution. Switch over to the S3 backed apt mirror for that region. Why these aren’t the default, who knows.

Step 1: Throw this in your instance’s USER_DATA:

sed -i -e "s/${EC2_REGION}${EC2_REGION}" /etc/apt/sources.list
apt-get update

Step 2: Enjoy much faster apt-get.

Step 3: There is no step 3.

comments powered by Disqus