It took a couple of days, but I finally found out how to configure linux in order to run Amazon EC2 Tools commands. I found some instructions here and there, but I’ll provide instructions that are clearer (I hope) to the new Linux user, particularly, running Fedora (RPM-based Linux). Much of it is derived from the aforelinked instructions, so look at those for extra information. You should already know some basic linux commands – and remember that these instructions worked for me in Fedora.
First of all, what is Amazon EC2?
It’s a web service by Amazon that provides resizable (i.e. ‘elastic’) processing capacity in the cloud. You can read all about it on the Amazon AWS site
Why do I need it?
It’s mainly used as a scalable platform for web applications, and you only pay what you use (bandwidth and cores-per-hour). You can basically use it to harness scalable processing power at your own disposal. I intend to use EC2 as a virtual render farm. Conveniently, there’s an AMI available for rendering in mental ray, called mental cloud direct
. I’m sure more 3D-specialized AMIs will be popping up.
There’s already a GUI on their website (AWS Console), why should I use the Amazon EC2 API tools in Terminal?
To do fun programming things!
Let’s do this.
2. Under Account, click on “Security Credentials” and go to “Access Credentials”.
3. Create a new Access Key and a new Certificate (X.509), if you haven’t already done so. These should generate:
– a PEM encoded X.509 certificate named something like cert-xxxxxxx.pem
– a PEM encoded RSA private key named something like pk-xxxxxxx.pem
4. Download both these files.
5. Download the Amazon EC2 API Tools from here
6. Open Terminal and in your home folder, create a hidden folder called ec2
[username@local-PC ~]$ mkdir .ec2
7. Navigate to your downloads folder (or wherever your default downloads folder is).
[username@local-PC ~]$ cd Downloads
8. Extract the ec2-api-tools.zip file to the .ec2 folder.
[username@local-PC Downloads]$ unzip ec2-api-tools.zip -d ~/.ec2
9. Move the PEM files to the .ec2 folder.
[username@local-PC Downloads]$ mv *.pem ~/.ec2
10. Check the .ec2 folder. You should have the two PEM files and the extracted ec2-api-tools folder (which, in my case, is called “ec2-api-tools-1.3-62308”).
[username@local-PC Downloads]$ cd ~/.ec2
[username@local-PC .ec2]$ ls
11. Move the directories “bin” and “lib” from the ec2-api-tools folder (in my case, “ec2-api-tools-1.3-62308”) to the .ec2 folder.
[username@local-PC .ec2]$ cd ec2-api-tools-1.3-62308
[username@local-PC ec2-api-tools-1.3-62308]$ mv bin lib ..
12. Now we will need to set some environment variables. So, become root. Before moving on though, you might want to read about becoming root
as it’s slightly different for other linux distributions such as Ubuntu.
[username@local-PC ec2-api-tools-1.3-62308]$ su –
13. Make sure the file .bash_profile is in the root directory (using the ‘-a’ flag to list hidden files)
[root@local-PC ~]# ls -a
If you like, see what’s inside this file. It’s fascinating.
[root@local-PC ~]# cat .bash_profile
14. Add environment variables to .bash_profile (Note: Don’t confuse the backtick ` with the single quote ‘ !)
[root@local-PC ~]# echo ‘# Setup Amazon EC2 Command-Line Tools’ >> .bash_profile
[root@local-PC ~]# echo ‘export EC2_HOME=/home/username/.ec2’ >> .bash_profile
[root@local-PC ~]# echo ‘export PATH=$PATH:$EC2_HOME/bin’ >> .bash_profile
[root@local-PC ~]# echo ‘export EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem` ‘ >> .bash_profile
[root@local-PC ~]# echo ‘export EC2_CERT=`ls $EC2_HOME/cert-*.pem` ‘ >> .bash_profile
** Important! Notice for the EC2_HOME path, I used “/home/username/.ec2”. You must change the “username” according to your directory’s name – where you created the .ec2 folder in step 6. **
15. Check the file to make sure it was all set fine
[root@local-PC ~]# cat .bash_profile
16. Set up Java (Note: This involves removing default java from your system.)
[root@local-PC ~]# yum remove java java-devel
17. Navigate to the “/usr” directory and make a java directory
[root@local-PC ~]# cd /usr
[root@local-PC usr]# mkdir java
18. Navigate to the newly created java directory and download the latest Java.
[root@local-PC usr]# cd java
Note: You can use an arbitrary name (safe .bin) in front of the ‘-O’ flag. In this case, I’ve used “jre-rpm.bin”. For the download address, I just used the URL from the Linux RPM download in the Java site
. You can do some other things with wget
19. Change the permissions of the file you downloaded to be executable and unpack it
[root@local-PC java]# chmod a+x jre-rpm.bin
[root@local-PC java]# ./jre-rpm.bin
Note: In this case, it unpacked a file called “jre-6u24-linux-i586.rpm”
20. Start installation process, which will create a folder called “jre1.6.0_24” in this case.
[root@local-PC java]# rpm -iv jre-6u24-linux-i586.rpm
21. Now set final environment variable in .bash_profile.
[root@local-PC java]# echo ‘export JAVA_HOME=/usr/java/jre1.6.0_24’ >> ~/.bash_profile
22. Almost done… just reload your .bash_profile
[root@local-PC java]# source ~/.bash_profile
23. Start using EC2 commands
! You can start with a command to display all Amazon-owned images. (Note: You don’t have to change your working directory, but still must be root.)
[root@local-PC java]# ec2-describe-images -o amazon
We can continue trying things with the EC2 commands, but I’ll stop here. For example, look under “Creating and Connecting to a Server Instance” in Robert Sosinski’s tutorial
. I hope it works for you. If you have any questions, email me
. As I’m still learning Linux, there might be a more proper way. I need food.