How I Created an Amazon AMI for Faster Deployments
The content of this article was originally written by Reed Law on the Smashing Boxes blog.
Chef is a great tool for automating deployment. But the bootstrap process is hard to get right. Sometimes it can just be easier to start with a system that’s already configured close to your needs.
- 64-bit 2011.09 Amazon Linux with EBS boot
- Nginx latest stable
- Ruby 1.9.3
First launch an instance from the AWS Management Console. I am using amzn-ami-2011.09.2.x86_64-ebs (ami-1b814f72) as the image.
$ ssh ~/.ec2/yourkey email@example.com $ sudo su $ yum update -y $ yum install -y openssl-devel zlib-devel gcc gcc-c++ make autoconf readline-devel curl-devel expat-devel gettext-devel pcre-devel $ wget http://nginx.org/download/nginx-1.0.14.tar.gz $ tar xvzf nginx-1.0.14.tar.gz $ cd nginx-1.0.14 $ ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module $ make $ make install
Now you will probably want an init script. This Slicehost article is a bit old but still works beautifully. Start at the “Init Script” section.
Now for ruby, install yaml for psych, and then compile ruby from source:
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz $ tar xzvf yaml-0.1.4.tar.gz $ cd yaml-0.1.4 $ ./configure --prefix=/usr/local $ make && make install $ wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz $ tar xvzf ruby-1.9.3-p125.tar.gz $ cd ruby-1.9.3-p125 $ ./configure --prefix=/usr/local --disable-install-doc --with-opt-dir=/usr/local/lib $ make && make install $ /usr/local/bin/gem install bundler
Now clean up:
$ rm -rf ruby* nginx* yaml* $ cd /var/log $ > cron $ > maillog $ > secure $ > spooler $ > yum.log $ rm ~/.bash_history $ exit
Now we’re ready to create the image. Right click on the EC2 instance in the AWS control panel and choose “Create Image (EBS AMI)”. Give it a name and description and then click “create”. Now choose the AMIs tab on the left. You should see the new AMI in the “pending” status.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)