Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Setting up shop with Boto

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

Setting up shop with Boto

Cologne AWS User Group, 2015-07-23

Avatar for Otto Poellath

Otto Poellath

July 23, 2015

Other Decks in Programming

Transcript

  1. What is Boto? Why would I use it? How do

    I use it? What does it look like in practice?
  2. What is Boto? • AWS SDK for Python • Supports

    ~50 AWS services • Boto 3 has been released recently • AWS CLI is based on Boto 3 • Suitable for infrastructure automation and application development
  3. What are the alternatives? • Other AWS SDKs • fog

    • CloudFormation • Terraform • Many others…
  4. Why would I choose Boto? • Does your team have

    Python skills? • What services do you need to work with? • Do you want to write applications and tools, or automate your infrastructure?
  5. How do I use it? import boto3 s3 = boto3.resource('s3')

    bucket = 'existing-bucket' file = 'boto.jpg' b = s3.Object(bucket, file) b.put(Body=open(file, 'rb'))
  6. What’s in the box? botocore Session Credentials Clients HTTPS Authentication

    Serialization Response handling Pagination Waiters boto3 Session Config Resources Clients Collections Events
  7. Clients - low level API ec2 = boto3.client('ec2') r =

    ec2.create_vpc(CidrBlock='10.0.0.0/16') vpc_id = r['Vpc']['VpcId'] tags = [] tags.append({'Key': 'acme:env', 'Value':'woot'}) tags.append({'Key': 'acme:role','Value':'vpc'}) ec2.create_tags(Resources=[vpc_id], Tags=tags)
  8. Paginators r = ec2.describe_tags() for tag in r['Tags']: print tag['Key']

    p = ec2.get_paginator('describe_tags') for page in p.paginate(): for tag in page['Tags']: print tag['Key']
  9. Resources - higher-level API ec2 = boto3.resource('ec2') vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')

    subnet = vpc.create_subnet(CidrBlock='10.0.0.0/24') subnet.delete() vpc.delete()
  10. What does it look like in practice? • We used

    Boto to setup and tear down environments on demand • An environment is a named VPC spanning multiple availability zones • It contains several Beanstalk apps, RDS, Cassandra and Elasticache instances as well as network and security related resources
  11. What does it look like in practice? • AWS Api

    is low-level, so you end up building your own abstractions on top of Boto • When automating infrastructure, it becomes essential to manage dependencies between resources • You’ll notice the first time you cannot delete a resource…