Difference between revisions of "Amazon EC2"
(→Start) |
|||
Line 8: | Line 8: | ||
=== Start === | === 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 | + | 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. The instance id is then stored in a variable and used to assign the elastic IP address to it after a delay.<br> |
+ | <br> | ||
+ | The timeout commands works on Vista but you may need to replace it with a something else on other OS flavors (ping perhaps?). At first I did not have a delay at all, but ran into sporadic trouble where the instance ID might not be recognized by ec2 if you try to assign an IP to it too soon. | ||
<pre> | <pre> | ||
@echo off | @echo off | ||
Line 19: | Line 21: | ||
echo to check status run status.bat (startup usually take a couple of minutes) | 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- | + | for /f "skip=1 tokens=2" %%i in ('c:\ec2\bin\ec2-run-instances ami-af51b0c6 -k wowza-keypair -t m1.small -f c:\ec2\includes\live.zip') do set INSTANCE=%%i |
+ | echo. | ||
+ | echo waiting 30 seconds before assigning static IP | ||
+ | timeout /t 30 /nobreak | ||
+ | c:\ec2\bin\ec2-associate-address -i %INSTANCE% 123.123.123.123 | ||
</pre> | </pre> | ||
Revision as of 19:26, 10 December 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 assume that you will only launch 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. The instance id is then stored in a variable and used to assign the elastic IP address to it after a delay.
The timeout commands works on Vista but you may need to replace it with a something else on other OS flavors (ping perhaps?). At first I did not have a delay at all, but ran into sporadic trouble where the instance ID might not be recognized by ec2 if you try to assign an IP to it too soon.
@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-af51b0c6 -k wowza-keypair -t m1.small -f c:\ec2\includes\live.zip') do set INSTANCE=%%i echo. echo waiting 30 seconds before assigning static IP timeout /t 30 /nobreak c:\ec2\bin\ec2-associate-address -i %INSTANCE% 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