tag:blogger.com,1999:blog-8885167082319491081.post-64461173665412820412008-04-09T18:58:00.007-04:002008-04-09T19:22:20.380-04:002008-04-09T19:22:20.380-04:00Getting Started with EC2<p>
Wow is EC2 fussy. You know this already. Such is life when using public-key encryption. if you are just getting started, the following greatly simplifies the situation. It won't handle multiple accounts or multiple instances, but sometimes one is all you need.
</p>
<p>
First, go through the stock EC2 tutorial. And then compile all the keys and stuff into one spot like so:
</p>
<pre>
export S3_PUBLIC='your s3 public key'
export S3_PRIVATE='your s3/private key'
export EC2_PRIVATE_KEY='./pk-YOURCERT.pem' # somewhere
export EC2_CERT='./cert-YOURCERT.pem' # somewhere
export EC2_HOME='./ec2-api-tools-1.3-19403' # OR SOMETHING
export PATH=$EC2_HOME/bin:$PATH
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/home
export AMI='ami-226e8b4b' # or something
export EC2_SSH_KEY=yourname-keypair
</pre>
<p>
Ok, now the following functions make it simple to start stop and login
</p>
<pre>
# VERSION 3 -- now with ec2do
# VERSION 2 -- now with push/pull
function ec2start {
ec2-run-instances $AMI -k $EC2_SSH_KEY
}
function ec2list {
ec2-describe-instances
}
function ec2host {
# it's one line below
ec2-describe-instances | grep INSTANCE | grep amazonaws.com | head -n 1 | awk '{print $4}'
}
function ec2id {
# it's one line below
ec2-describe-instances | grep INSTANCE | grep amazonaws.com | head -n 1 | awk '{print $2}'
}
function ec2stop {
echo "Stopping..."
ec2-terminate-instances `ec2id`
}
function ec2login {
ssh -i id_rsa-$EC2_SSH_KEY root@`ec2host`
}
function ec2push {
scp -i id_rsa-$EC2_SSH_KEY $1 root@`ec2host`:~/
}
function ec2pull {
scp -i id_rsa-$EC2_SSH_KEY root@`ec2host`:$1 .
}
function ec2do {
ssh -i id_rsa-$EC2_SSH_KEY root@`ec2host` $@
}
function ec2help {
echo "haha"
echo ""
echo "ec2list -- alias for ec2-describe-instances"
echo "ec2start -- starts one instance"
echo "ec2stop -- stops an instance"
echo "ec2id -- lists the reservation id of a running instance"
echo "ec2host -- lists the host of a running instance"
echo "ec2login -- log in to running instance"
echo "ec2push localfile -- push a file to remote homedir"
echo "ec2pull remote -- pull a remote file to local current dir"
echo "ec2do cmds -- execute a command remotely"
}
</pre>
<p>
Put all of that into your profile, and you'll be all set. Enjoy..
</p>nickghttp://www.blogger.com/profile/04659163622120256748noreply@blogger.com0