I'm using Mac OS X and running instances in the EU West Region. My instances are of the Amazon Linux AMI.
Installing the EC2 command line tools
Having command-line tools installed is a supplement to the AWS management console found online. I found a good tutorial about how to get started with the tools for EC2 on Mac OS X.
After downloading the tools from Amazon download site, the tutorial describes how to set environment variables and how to create X.509 certificates etc.
The only detail missing was that I'm running my instances in the EU West region. I found a hint in another tutorial on setting an additional environment variable. My resulting .profile file looks like this:
# Setup Amazon EC2 Command-Line Tools export EC2_HOME=~/.ec2 export PATH=$PATH:$EC2_HOME/bin export EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem` export EC2_CERT=`ls $EC2_HOME/cert-*.pem` export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/ # This line is from second tutorial, for use with EU West Region: export EC2_URL=https://eu-west-1.ec2.amazonaws.com
The first tutorial show many examples of using the command-line tools to start instances, open ports etc.
Package manager for Amazon Linux AMI
Maybe the tools can be used to install packages on the Amazon Linux AMI instance, but you could also use a package manager.
Amazon Linux AMI comes with the yum package manager installed. A tutorial which is specifically aimed at installing PHP on a Amazon Linux AMI instances also gives a quick tour of yum. Basically you do like this:
$ sudo yum install <PACKAGE_NAME>
Installing Apache Web Server
As an example of using the EC2 tools and the yum package manager is installing the Apache Web Server. The command ec2-describe-instances lists running instances in the region given in the environment variable EC2_URL.
$ ec2-describe-instances RESERVATION r-xxxxxxxx xxxxxxxxxxxxx default INSTANCE i-xxxxxxxx ami-xxxxxxx ec2-xx-xxx-xx-xx.eu-west-1.compute.amazonaws.com
default is the name of the security group for the instance. You may have used a different security group name. Security groups are used to make it easier to apply a set of permissions to a range of instances. The command ec2-authorize applies a permission to a security group, like opening up port 80 for httpd.
# open up port 80 on instances belonging to security group 'default' $ ec2-authorize default -p 80 PERMISSION default ALLOWS tcp 80 80 FROM CIDR 0.0.0.0/0
Logging into the instance with ssh and then using the package manager to install httpd.
# use the key pair that you used when launcing your instance $ ssh -i ~/.ec2/ec2-keypair email@example.com # install httpd - starts an install process $ sudo yum install httpd