Guest User

Untitled

a guest
Feb 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Authorize TCP, SSH & ICMP for default Security Group
  4. #ec2-authorize default -P icmp -t -1:-1 -s 0.0.0.0/0
  5. #ec2-authorize default -P tcp -p 22 -s 0.0.0.0/0
  6.  
  7. # The Static IP Address for this instance:
  8. IP_ADDRESS=$(cat ~/.ec2/ip_address)
  9.  
  10. # Create new t1.micro instance using ami-cef405a7 (64 bit Ubuntu Server 10.10 Maverick Meerkat)
  11. # using the default security group and a 16GB EBS datastore as /dev/sda1.
  12. # EC2_INSTANCE_KEY is an environment variable containing the name of the instance key.
  13. # --block-device-mapping ...:false to leave the disk image around after terminating instance
  14. EC2_RUN_RESULT=$(ec2-run-instances --instance-type t1.micro --group default --region us-east-1 --key $EC2_INSTANCE_KEY --block-device-mapping "/dev/sda1=:16:true" --instance-initiated-shutdown-behavior stop --user-data-file instance_installs.sh ami-cef405a7)
  15.  
  16. INSTANCE_NAME=$(echo ${EC2_RUN_RESULT} | sed 's/RESERVATION.*INSTANCE //' | sed 's/ .*//')
  17.  
  18. times=0
  19. echo
  20. while [ 5 -gt $times ] && ! ec2-describe-instances $INSTANCE_NAME | grep -q "running"
  21. do
  22. times=$(( $times + 1 ))
  23. echo Attempt $times at verifying $INSTANCE_NAME is running...
  24. done
  25.  
  26. echo
  27.  
  28. if [ 5 -eq $times ]; then
  29. echo Instance $INSTANCE_NAME is not running. Exiting...
  30. exit
  31. fi
  32.  
  33. ec2-associate-address $IP_ADDRESS -i $INSTANCE_NAME
  34.  
  35. echo
  36. echo Instance $INSTANCE_NAME has been created and assigned static IP Address $IP_ADDRESS
  37. echo
  38.  
  39. # Since the server signature changes each time, remove the server's entry from ~/.ssh/known_hosts
  40. # Maybe you don't need to do this if you're using a Reserved Instance?
  41. ssh-keygen -R $IP_ADDRESS
  42.  
  43. # SSH into my BRAND NEW EC2 INSTANCE! WooHoo!!!
  44. ssh -i $EC2_HOME/$EC2_INSTANCE_KEY.pem ubuntu@$IP_ADDRESS
Add Comment
Please, Sign In to add comment