Follow-up on Ubuntu apt sources.list in Amazon Web Services

This is a follow-up to a previous post where I was having trouble running apt-get as part of the initial boot process for a new AWS instance.

I actually never could automatically load packages using the recommended workaround of using apt_mirror :


#cloud-config
apt_mirror: http://us.archive.ubuntu.com/ubuntu/

When I'd check the cloud-init log at /var/log/ apt-get would just sort of silently fail.

I'm still not sure of what the exact issue was, but it seems like part of the problem is a latency issue regarding when the DNS servers come online.

My solution was to go with a Bash script for EC2 user-data and put in a sleep period. Using the following I could get packages to load on startup as expected.


#!/bin/bash
sleep 30s
sed -i -e 's/us-west-2.ec2/us/' /etc/apt/sources.list
log='/tmp/init.log'
apt-get update &>> $log
apt-get install -y apache2 &>> $log