And that’s just the tip of the iceberg. However sometimes you need to use the command line tools because you want to script a task, or access features that a GUI tool doesn’t provide access to. For example today I became motivated to finally get comfortable with the EC2 API so I could create a Elastic Load Balancer instance to test the new functionality provided.
I found lots of tutorials and guidance on setting up your Linux machine to run the tools. Unfortunately Windows is a 2nd class citizen on AWS. This is true pretty much across the board from command line tools, to Windows instances (just made available last October, still on Win2k3, etc).
So here is the “definitive guide” to setting up your Windows machine to run the EC2 API command line tools:
The first requirement is to have Java 5 or later installed. If you don’t already have Java installed for some reason go to http://www.java.com/en/download/manual.jsp#win.
Create a folder called AWS somewhere. I like to make it easy to get to so I created it at d:aws. You can really call this folder whatever you want, but it will be where you store your certificates, your services API files, etc.
Authentication to AWS happens via a certificate and private key. You’ll need to retrieve these files from AWS.
Go to http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key and then scroll down to the X.509 area. You’ll need to create a new certificate. Once you do they’ll provide you a Private Key File (pk-
KEEP THESE FILES PRIVATE. Possession of these two files give you access to your AWS account.
Now you need to configure your command line environment with a few environment variables. Create a batch file in d:aws called awsTools.bat. Edit this file with the following text:
REM Path should have binjava.exe under it
set JAVA_HOME=”C:Program Files (x86)javajre6″
REM Path to Primary Key and Certificate retrieved from AWS
REM Path to EC2 API, subfolders of bin and lib
REM Path to ELB API, subfolders of bin and lib
JAVA_HOME will need to be set to the appropriate path for your machine. If you’re confused about where exactly JAVA_HOME should point to find java.exe. It will be a in a folder called bin. You want to set JAVA_HOME to the parent directory of bin.
For example on my system you would find java.exe at “C:Program Files (x86)javajre6binjava.exe” so I set JAVA_HOME to “C:Program Files (x86)javajre6”
EC2_Private_Key and EC2_Cert both are the location of the private key and certificate that you retrieved from the AWS website in the previous step. I renamed my key and certificate for simplicities sake. If you have multiple AWS accounts all you need to do is modify these lines to switch between accounts.
EC2_HOME and AWS_ELB_HOME both point to the folders you unzipped the API into. Both folders should have two subdirectories called bin and lib. Bin will contain the cmd files of the different commands for that API. You set the path variable to include these cmd files in your path so that you do not have to be in that directory to run them.
Now you only need to run the batch file to get a command line with the environmental variables set. You also could permanently set these variables and have them available in any command window if you choose. If you want to get fancy you could even put in the logic to set the paths based on the current directory of the batch file, and then put the folder on a thumb drive and carry it around.
If you run awsTools.bat you should have a command prompt that you can run the EC2 tools from. A simple command to test is “ec2-describe-regions”:
REGION eu-west-1 eu-west-1.ec2.amazonaws.com
REGION us-east-1 us-east-1.ec2.amazonaws.com
If you get an error running this command then you need to go back and verify your installation.
I have found the Quick Reference Cards provided by Amazon to be extremely useful. They can be found at http://aws.amazon.com/documentation/ for all the various services.
Bạn mong muốn gì sau những giờ làm việc căng thẳng? Đi chơi, nghe nhạc hay shopping? Còn nếu...
Amazon Elastic Load Balancer Setup May 20th, 2009 As I previously wrote about, Amazon announced a load balancing solution...
Retrieving Current Users E-mail Address from Active Directory April 7th, 2009 I’ve seen several examples online of how to...
One Piece không chỉ là bộ truyện tranh thông thường mà còn là tuổi thơ của rất nhiều người....