Welcome to a Better Boto!

Better Boto aims to reduce the burden of using AWS Boto3. AWS Boto3 is a low level SDK for interacting with AWS Services and sometimes it feels too low level or too crud like.

Better Boto is a collection of helper functions to make using AWS Boto easier. For example, it added a create_or_update method to the AWS CloudFormation client. It also provides some helpers for dealing with pagination operations and some help using AWS Organizations. Check out the API for more info.

Client

What is this?

With the following clients you can use them as context managers and they provide extra functionality for you. Each client is documented below:

Classes

class betterboto.client.ClientContextManager(service_name, **kwargs)[source]

ClientContextManager allows you to use boto3 client as a python context manager. This allows you to perform the following:

with ClientContextManager('cloudformation') as cloudformation_client:
    cloudformation_client.create_stack(**args)
class betterboto.client.CrossAccountClientContextManager(service_name, role_arn, role_session_name, **kwargs)[source]

CrossAccountClientContextManager allows you to use boto3 client as a python context manager for another account. This allows you to perform the following:

with CrossAccountClientContextManager(
    'cloudformation',
    'arn:aws:iam::0123456789010:role/deployer',
    'deployment_account_session',
) as deployment_account_cloudformation:
    deployment_account_cloudformation.create_stack(**args)
class betterboto.client.MultiRegionClientContextManager(service_name, regions, **kwargs)[source]

MultiRegionClientContextManager allows you to use boto3 client as a python context manager for multiple regions. This allows you to perform the following:

with MultiRegionClientContextManager('cloudformation', ['us-east-1','eu-west-1']) as cloudformation_clients:
    for region_name, cloudformation_client in cloudformation_clients.items():
        cloudformation_client.create_stack(**args)

If you want to deploy to multiple regions at the same time then you should use Python Threads

CloudFormation helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.cloudformation.create_or_update(self, **kwargs)[source]

For the given template and stack name, this method will create a stack if it doesnt already exist otherwise it will generate a changeset and then execute it. This method will wait for the operation to complete before returning and in the instance of an error it will print out the stack events to help you debug more easily.

Parameters
  • self – cloudformation client

  • kwargs – these are passed onto the create_stack and create_change_set method calls

Returns

None

Organizations helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.organizations.convert_path_to_ou(self, path)[source]

This method accepts a path and returns the ou. This raises an exception when converting / and you have more than one root

Parameters
  • self – organizations client

  • path – organizations path

Returns

the ou of the path specified

betterboto.organizations.list_accounts_single_page(self, **kwargs)[source]

This will continue to call list_accounts until there are no more pages left to retrieve. It will return the aggregated response in the same structure as list_accounts does.

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_accounts method call

Returns

organizations_client.list_accounts.response

betterboto.organizations.list_children_nested(self, **kwargs)[source]

This method will return a list of all children (either ACCOUNT or ORGANIZATIONAL_UNIT) for the given ParentId. It includes children, grandchildren lower levels of nesting.

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_children method call

Returns

list of children in the structure of [{‘Id’: “0123456789010”}, {‘Id’: “1009876543210”}]

betterboto.organizations.list_children_single_page(self, **kwargs)[source]

This will continue to call list_children until there are no more pages left to retrieve. It will return the aggregated response in the same structure as list_children does.

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_children method call

Returns

organizations_client.list_children.response

Service Catalog helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.servicecatalog.list_portfolios_single_page(self, **kwargs)[source]

This will continue to call list_portfolios until there are no more pages left to retrieve. It will return the aggregated response in the same structure as list_portfolios does.

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_portfolios method call

Returns

servicecatalog_client.list_portfolios.response

betterboto.servicecatalog.list_provisioning_artifacts_single_page(self, **kwargs)[source]

This will continue to call list_provisioning_artifacts until there are no more pages left to retrieve. It will return the aggregated response in the same structure as list_provisioning_artifacts does.

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_provisioning_artifacts method call

Returns

servicecatalog_client.list_provisioning_artifacts.response

betterboto.servicecatalog.search_products_as_admin_single_page(self, **kwargs)[source]

This will continue to call search_products_as_admin until there are no more pages left to retrieve. It will return the aggregated response in the same structure as search_products_as_admin does.

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the search_products_as_admin method call

Returns

servicecatalog_client.search_products_as_admin.response