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
{ | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": ["s3:ListBucket"], | |
"Resource": ["arn:aws:s3:::pyconprod"] | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": ["s3:GetObject"], |
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
import boto | |
# Create a connection to the Identity & Access Management Service | |
iam = boto.connect_iam() | |
# Create a new user | |
user_data = iam.create_user('pycon') | |
# Create a new group | |
group_data = iam.create_group('pythonistas') |
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
import boto.vpc | |
import time | |
REGION_NAME = 'us-west-2' | |
AMI_ID = 'ami-8e27adbe' # Amazon Linux AMI | |
conn = boto.vpc.connect_to_region(REGION_NAME) | |
# Create a VPC | |
vpc = conn.create_vpc('10.0.0.0/16') |
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
import boto.ec2 | |
import boto.ec2.elb | |
for region in boto.ec2.regions(): | |
ec2_conn = region.connect() | |
elb_conn = boto.ec2.elb.connect_to_region(region.name) | |
# do stuff with EC2 and ELB for this region here |
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
from boto.s3.lifecycle import Lifecycle, Transition, Rule | |
import boto | |
c = boto.connect_s3() | |
b = c.lookup('mybucket') | |
t = Transition(days=0, storage_class='GLACIER') | |
r = Rule('foo rule', 'foo', 'Enabled', 1, t) | |
l = Lifecycle() | |
l.append(r) |
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
# | |
# EC2 returns a list of Reservation objects when you call DescribeInstances. | |
# Usually, you just want the Instance objects that are embedded in the | |
# Reservation object. This shows how to use the magic of nested list | |
# comprehensions to construct a one-liner to get the Instance objects. | |
>>> import boto | |
>>> ec2 = boto.connect_ec2() | |
>>> reservations = ec2.get_all_instances() | |
>>> instances = [i for r in reservations for i in r.instances] | |
>>> |
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
[Boto] | |
# Add this line to your boto config file in the Boto section | |
https_validate_certificates = False |
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
import boto | |
from boto.s3.connection import OrdinaryCallingFormat | |
c = boto.connect_s3(calling_format=OrdinaryCallingFormat()) |
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
In [1]: policy = """{ | |
...: "Statement":[{ | |
...: "Effect":"Allow", | |
...: "Action":["s3:*"], | |
...: "Resource":["arn:aws:s3:::mybucket"]}]}""" | |
In [2]: import boto | |
In [4]: c = boto.connect_iam() | |
In [5]: instance_profile = c.create_instance_profile('myinstanceprofile') | |
In [6]: role = c.create_role('myrole') | |
In [7]: c.add_role_to_instance_profile('myinstanceprofile', 'myrole') |
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
In [1]: import boto | |
In [2]: c = boto.connect_s3() | |
In [3]: b = c.lookup('stats.pythonboto.org') | |
In [4]: k = b.new_key('test1234') | |
In [5]: def mycb(so_far, total): | |
...: print '%d bytes transferred out of %d' % (so_far, total) |