Creating an AMI on EC2

From Genome Analysis Wiki
Jump to navigationJump to search

Notes About Creating a New EC2 AMI

Back to parent: GotCloud

The following are notes taken when creating the Amazon Machine Instance used for the CSG pipeline process. These notes assume you have already created an EC2 account and have the certificates and keys set up properly.

Launch an instance

 Login to https://console.aws.amazon.com/ec2       # EC2 Management Console

Pay attention to the region you are using, at least for now it seems any StarCluster activity must be in us-east-1. Launch a new instance which we will use to set up the software and ultimately save it as an AMI.

 EC2 DashBoard -> Launch Instance
 Class Wizard
 Ubuntu Server 12.04.1 LTS   64 bit
 Instance type -> Micro,  EC2, no preference        # Memory size does not matter
 Advanced Instance Options  (take defaults)
 Storage Device Configuration -> Edit
 Change volume to 30G -> Save -> Continue           # Storage size does not matter
 Key Name = GotCloud 1.06a
 Create Key/Pair if you need to, Name the PEM and save the pem file for access by ssh
 Choose a Security Group  (take default)
 Launch
   No need to Create Status Check Alarms
   No need to Create EBS Volumes

Set Up Swap Space

Issue the command swapon -s to see if there is swap space. If there is only a header line, you need to add a swap file like this:

 df -h          # Be sure there's enough space, decide on swap size
 #  Create a file /swap to use (assuming / is large enough)
 sudo bash      # Run these commands as root
 swap=/swap
 dd if=/dev/zero of=$swap bs=1073741824 count=15    # 15GB swap
 chown root:root $swap
 mkswap $swap
 chmod 0600 $swap
 swapon $swap
 echo "$swap  none swap sw  0  0" >> /etc/fstab

 swapon -s       # Should show the swap device

Install the Software

(1) There are a number of additional Debian packages that you may well need, so we make sure they are all installed.

 sudo apt-get update
 sudo apt-get upgrade           # Apply maintenance

 sudo apt-get install java-common default-jre make libssl0.9.8 
 sudo apt-get install libnet-amazon-ec2-perl s3cmd
 sudo apt-get install make g++ libcurl4-openssl-dev libssl-dev libxml2-dev libfuse-dev

(2) S3fs allows one to access S3 storage as a conventional file system. This can be quite handy, if it is set up properly. Our recent experience is that the 1000 Genomes data is has many files with incorrect permissions. Still if you're lucky, your data will be useful. Install the software like this:

 mkdir -p ~/src
 cd ~/src
 wget  http://s3fs.googlecode.com/files/s3fs-1.68.tar.gz
 tar xzvf s3fs-1.68.tar.gz
 cd s3fs*
 ./configure
 sudo make install

(3) Follow the instructions to install the GotCloud Debian packages Run the tests to be sure everything is OK.

Configure the Host to be Usable

It is useful to configure /etc/rc.local to do most things you need at boot time. There are many other ways to do this, but here's one simple way - create the file /etc/rc.local (as root). The following example sets up access details for s3cmd and s3fs (use your own credentials).

ubuntu@ip-10-254-60-210:~$ sudo more /etc/rc.local

 #!/bin/sh 
 USER=ubuntu
 THOUSANDG=/mnt/1000g
 FILES3=passwd-s3fs
 S3ERR=/tmp/s3fs.err

 #    Set up for GotCloud    Assumes /dev/xvdf has reference files for GotCloud
 mkdir -p /gotcloud
 mount /dev/xvdf /gotcloud
 if [ ! -d /gotcloud/gotcloud.ref ]; then
   echo "#######################################################"
   echo "#   GotCloud is not set up on /gotcloud"
   echo "#######################################################"
 fi

 #    Setup 1000g access by s3fs
 usermod -aG fuse $USER
 echo 'AKIAIW5TQEUWZ3YCZF2Q:ft1eJa3WGzNE8iitNlbA08x/G8iMqkMIkJjFCIGf' > /etc/$FILES3
 chown root.root /etc/$FILES3
 chmod 640 /etc/$FILES3
 mkdir -p $THOUSANDG
 chown $USER.$USER $THOUSANDG
 #   It is tempting to use caching with  -o use_cache=/tmp 1000genomes
 #   But s3fs cache is exceedingly dumb and does not use a least recently used
 #   mechanism -- which will guarantee your root volume will fill up
 /usr/local/bin/s3fs -o allow_other 1000genomes $THOUSANDG > $S3ERR 2>&1
 if [ ! -r $THOUSANDG/alignment.index ]; then
   echo "#######################################################" >> $S3ERR
   echo "#   1000genomes is not set up on $THOUSANDG" >> $S3ERR
   echo "#######################################################" >> $S3ERR
 fi
 df -h

 exit 0

Create the AMI

Once your instance is all ready with the files you want, swap space etc, then create the AMI. In your browser at the EC2 Management Console do the following:

 Create Image
   Image Name   csg-biopipe_instance
   Image Description:  Image for CSG Biopipe instance
   Volume Size:  30GB
   Take defaults otherwise

This will take several minutes to complete. In the EC2 Dashboard, you can monitor the progress. When it is done, you'll see a new AMI under the list of AMIs.

Your new AMI should look pretty much like this:

 AMI: 	Ubuntu Cloud Guest AMI ID ami-3d4ff254 (x86_64)
 Name: 	Ubuntu Server 12.04.1 LTS 	 
 Description: 	Ubuntu Server 12.04.1 LTS with support available from Canonical (http://www.ubuntu.com/cloud/services).
 Number of Instances: 	1 	 
 Availability Zone: 	No Preference 	 
 Instance Type: 	Micro (t1.micro) 	 
 Instance Class: 	On Demand 	Edit Instance Details
 EBS-Optimized: 	No
 Monitoring: 	Disabled 	Termination Protection: 	Disabled 	 
 Tenancy: 	Default 	 
 Kernel ID: 	Use Default 	Shutdown Behavior: 	Stop 	 
 RAM Disk ID: 	Use Default 	 
 Network Interfaces: 		 
 Secondary IP Addresses: 		 
 User Data: 		 
 IAM Role: 		Edit Advanced Details
 Key Pair Name: 	CSG 	Edit Key Pair
 Security Group(s): 	sg-a098e9c8 	Edit Firewall

Test the new AMI

Launch a new AMI instance and check that files are in the correct places. In the EC2 Management Console do:

 EC2 DashBoard -> AMIs -> Select CSG instance -> Launch Instance
 Launch Instances  (take defaults)
 Advanced Instance Options  (take defaults)
 Storage Device Configuration -> Edit
 Change volume to 30G or whatever -> Continue       # Defaults are OK
 Instance Details
   Key Name = test of instance
 Create Key/Pair if you need to, most likely you can use one you have created
 Choose a Security Group -> sg-a098e9c8 - quick-start-1
 Review -> Launch