Difference between revisions of "Amazon EC2"

From HeadBackup
Jump to navigationJump to search
 
Line 4: Line 4:
 
C:\Windows\System32\cmd.exe /k c:\ec2\start.bat
 
C:\Windows\System32\cmd.exe /k c:\ec2\start.bat
 
</pre>
 
</pre>
 +
 +
The tricky part here was reading in the instance ID in order to automatically assign the static IP after the instance launch.  These batch files may not behave as well if you launch more than one instance at a time.
  
 
=== Start ===
 
=== Start ===

Revision as of 07:13, 24 November 2009

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

The tricky part here was reading in the instance ID in order to automatically assign the static IP after the instance launch. These batch files may not behave as well if you launch more than one instance at a time.

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