import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1",
                                  aws_access_key_id='AKIAI56EJVPVWLMSRQSA',
                                  aws_secret_access_key='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')
#https://gist.github.com/esoupy/7832835
instance = conn.get_all_instances(instance_ids=['i-00a381d3ef2e7d53b'])
print "State", instance
# instance[0].instances[0].stop()
instance[0].instances[0].stop()
inst_state = instance[0].instances[0].state
print "STATUS",inst_state
# conn.stop_instances(instance_ids=['i-00a381d3ef2e7d53b'])

#reservations = conn.get_all_instances()
#print reservations
#instances = [i for r in reservations for i in r.instances]
#for i in instances:
    #instance = conn.get_all_instances(instance_ids=['i-00a381d3ef2e7d53b'])
    #inst_state = instance[0].instances[0].state
    #print inst_state
    # print("instance" ,i.__dict__)


# Security Groups
groups = conn.get_all_security_groups()
print "EC2 Security Groups :"
print groups
print
