Last active
December 27, 2015 11:09
-
-
Save shantanuo/7315883 to your computer and use it in GitHub Desktop.
create an instance dynamically using boto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| cat > create_image.py << heredoc | |
| import boto.ec2 | |
| myami='ami-eba0f882' | |
| mytype='t1.micro' | |
| myvolume='vol-cf5d9282' | |
| access='ABC' | |
| secret='xyz+pqr' | |
| conn = boto.ec2.connect_to_region("us-east-1", aws_access_key_id=access, aws_secret_access_key=secret) | |
| #myreservation=conn.run_instances(myami, placement='us-east-1a', key_name='nov15a',instance_type=mytype,security_groups=['NuoDB-1-0-1-AutogenByAWSMP-']) | |
| myreservation='r-6dad7e15' | |
| public_dns=conn.get_all_instances(filters={'reservation-id':myreservation})[0].instances[0].public_dns_name | |
| instance_id=conn.get_all_instances(filters={'reservation-id':myreservation})[0].instances[0] | |
| try: | |
| conn.attach_volume (myvolume, instance_id, '/dev/sdx') | |
| except: | |
| pass | |
| print public_dns | |
| print 'boto.ec2.connect_to_region("us-east-1", aws_access_key_id='+access+', aws_secret_access_key='+secret+')' | |
| print instance_id | |
| heredoc | |
| python26 create_image.py > instance_details.txt 2> instance_details_err.txt | |
| wget -N http://saraswaticlasses.net/sites/nov15a.pem > wget_standard.txt 2> wget_err.txt | |
| chmod 700 nov15a.pem | |
| public_ip=`head -1 instance_details.txt` | |
| instance=`tail -1 instance_details.txt` | |
| connectme=`tail -2 instance_details.txt | head -1` | |
| echo "copy-pate the following lines somewhere safe" | |
| echo "ssh -i nov15a.pem ec2-user@$public_ip" | |
| echo "import boto" | |
| echo $connectme | |
| echo "conn.terminate_instances(instance_ids=[$instance])" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment