Amazon EC2

From HeadBackup
Revision as of 08:00, 24 November 2009 by Andrew (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Amazon EC2 instance start, status and stop batch files

I currently use these batch files to start a Wowza server EC2 instance on Vista 32 bit edition. I have created shortcuts to the batch files using the following syntax so that the command prompts stay open after a user double clicks the shortcut.

C:\Windows\System32\cmd.exe /k c:\ec2\start.bat

Start

The following batch file will start an Amazon instance and automatically assign your elastic (static) IP address to it after the instance ID is assigned by Amazon. Just replace any environment or instance preferences and change to your own elastic IP. The most tricky part of this is the for command which first launches the instance and then extracts the instance id from line 2 (line 1 is skipped), field (token) 2 and assigns the elastic IP address to it.

@echo off
set JAVA_HOME="c:\Program Files (x86)\Java\jre6"
set EC2_HOME=c:\ec2
set PATH=%PATH%;%EC2_HOME%\bin
set EC2_PRIVATE_KEY=c:\ec2\keys\private.pem
set EC2_CERT=c:\ec2\keys\509.pem

echo to check status run status.bat (startup usually take a couple of minutes)

for /f "skip=1 tokens=2" %%i in ('c:\ec2\bin\ec2-run-instances ami-413fd828 -k wowza-keypair -t m1.small -f c:\ec2\includes\live.zip') do c:\ec2\bin\ec2-associate-address -i %%i 123.123.123.123

Status

This batch file simply checks the current instance status.

@echo off
set JAVA_HOME="c:\Program Files (x86)\Java\jre6"
set EC2_HOME=c:\ec2
set PATH=%PATH%;%EC2_HOME%\bin
set EC2_PRIVATE_KEY=c:\ec2\keys\private.pem
set EC2_CERT=c:\ec2\keys\509.pem

echo The instance id is i-something

c:\ec2\bin\ec2-describe-instances

Stop

This one finds the instance ID and then stops that instance. If you have multiple instances running it will stop each of them one by one (it will also generate some errors, but worked when I tested it).

@echo off
set JAVA_HOME="c:\Program Files (x86)\Java\jre6"
set EC2_HOME=c:\ec2
set PATH=%PATH%;%EC2_HOME%\bin
set EC2_PRIVATE_KEY=c:\ec2\keys\private.pem
set EC2_CERT=c:\ec2\keys\509.pem

echo After you stop the server verify that the status shows terminated with the status.bat command

for /f "skip=1 tokens=2" %%i in ('c:\ec2\bin\ec2-describe-instances') do c:\ec2\bin\ec2-terminate-instances %%i