Boto Python Amazon EC2

Amazon web services API for python, Boto 2.6.0, 2.9.5 and 2.9.6 for Python 2.7

 First, a sample boto python 2.7 script tested on Dreamhost with their installed boto 2.6 as well as boto 2.9.5 and 2.9.6 on Heroku. The Amazon keys are imported from our custom made cred2 module, which you will make yourself for your keys.

#!/usr/bin/python

import boto.ec2
import cred2

conn = boto.ec2.connect_to_region("us-east-1", \
    aws_access_key_id=cred2.awsaki(), aws_secret_access_key=cred2.awssak() )

# conn.start_instances('i-59999x2x')

reservations = conn.get_all_instances()
print reservations
for res in reservations:
  for isx in res.instances:
    print isx

 

substitute what the python 2.7 functions return with your keys

Your amazon keys can be found in your Amazon Web Services account

#!/usr/bin/python

def awsaki():
  return 'AKXXXXXXXXXXXXXXXXXX'

def awssak():
  return 'vvv999ccc888xxx777zzz666lll555kkk444z/'

We used awsaki which means Amazon Web Services Access Key ID or A.W.S.A.K.I. which is the best terminology to use in search engines to find information on digging this out of your account

Google this

Amazon Web Services Access Key ID

We used awssak which means Amazon Web Services Secret Access Key or A.W.S.S.A.K. which is good terminology to use in search engines to find information on digging this out of your account

Google this

Amazon Web Services Secret Access Key

 

Python 2.7 script to start an AWS instance that is stopped

#!/usr/bin/python

import boto.ec2
import cred2

conn = boto.ec2.connect_to_region("us-east-1", \
    aws_access_key_id=cred2.awsaki(), aws_secret_access_key=cred2.awssak() )

reservations = conn.get_all_instances()
rsx = reservations[0]
hsx = rsx.instances[0].start()

This works great if you have an AWS account with one instance, which is the one you want to start. So we aren’t creating an instance here, we are just starting an instance that has been stopped.

 

Now a minimal example in flask to pass boto results to the jinja template rendering modules

@app.route('/aws')
def awshm():
 x = zzcode.botoclass(); cvx = x.botofunc()
 return render_template('aws.html',navigation=navfunc(), contentVar=cvx )

 

Here we use boto in the class

class botoclass:
 def botofunc(self):
  import boto.ec2
  import credec2
  conn = boto.ec2.connect_to_region("us-east-1", \
    aws_access_key_id=credec2.awsaki(), aws_secret_access_key=credec2.awssak())
  reservations = conn.get_all_instances()
  cvx = list()
  for rsx in reservations:
   for isx in rsx.instances:
    cvx.append({'reservation': str(isx), 'status': str(isx.state), \
              'dns': str(isx.public_dns_name), 'ip': str(isx.ip_address) })
  return cvx

 

In the midst of a template in the templates directory named aws.html is this table

<TABLE>
<TR><TH>Reservation </TH><TH>Status </TH><TH>Domain </TH><TH>ip </TH></TR>
{% for item in contentVar %}
<TR>
 <TD>{{ item.reservation }}</TD>
 <TD>{{ item.status    }}</TD>
 <TD>{{ item.dns      }}</TD>
 <TD>{{ item.ip       }}</TD>
</TR>
{% endfor %}
              </TABLE>

 

0 thoughts on “Boto Python Amazon EC2”

  1. No matter how you do it, losing weight is an individual thing. Friends can help you but they ca not lose the weight for you. You have got to take charge of your weight loss from the beginning if you want to get serious about losing weight. The following tips will help.

  2. As you will inevitably learn on your path to losing weight, effective weight loss is not only about watching what you eat, but much more about changing your lifestyle. This means changing your habits and how you approach your day-to-day life. Read this information to help you throughout the process.

  3. I have learned newer and more effective things through your weblog. One other thing I would prefer to say is that often newer pc operating systems tend to allow far more memory to be utilized, but they as well demand more storage simply to work. If an individual is computer is not able to handle a lot more memory and the newest application requires that ram increase, it might be the time to shop for a new Computer system. Thanks

  4. sql interview questions
    sql interview questions and answers
    sql interview questions pdf
    sql interview questions for qa
    sql interview questions amazon
    sql interview questions 2019
    sql interview questions advanced
    sql interview questions facebook
    sql interview questions reddit
    sql interview questions data engineer
    sql interview questions difficult
    sql interview questions data analyst
    sql interview questions developer
    sql interview questions deloitte
    sql interview questions ddl dml
    sql interview questions download

    sql interview questions dataflair
    sql interview questions experienced
    sql interview questions examples
    sql interview questions employee table
    sql interview questions ey
    sql interview questions experienced pdf
    sql interview questions etl
    sql interview questions expedia
    sql interview questions for experienced professionals
    sql interview questions in amazon

Leave a Reply to Jamesgag Cancel reply

Your email address will not be published. Required fields are marked *