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.CrossMultipleAccountsClientContextManager(service_name, assumable_details, **kwargs)[source]

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

with CrossMultipleAccountsClientContextManager(
    'cloudformation',
    [
        ('arn:aws:iam::0123456789010:role/deployer', 'deployment_account_session'),
        ('arn:aws:iam::097167856333:role/deployer', 'deployment_account_session_nested'),
    ],
) 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

Budgets helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.budgets.describe_budgets_single_page(self, **kwargs)[source]

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

Parameters
  • self – budgets client

  • kwargs – these are passed onto the describe_budgets method call

Returns

budgets.describe_budgets.response

CloudFormation helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.cloudformation.create_or_update(self, ShouldUseChangeSets=True, ShouldDeleteRollbackComplete=False, **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

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the describe_stacks method call

Returns

servicecatalog_client.describe_stacks.response

betterboto.cloudformation.ensure_deleted(self, StackName)[source]

This will check if there is a stack with the given StackName in a state that can be deleted. If there is, it will delete it.

Parameters
  • self – cloudformation client

  • StackName – This is the name of the stack that should be deleted

Returns

None

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_stacks method call

Returns

servicecatalog_client.list_stacks.response

CodeBuild helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.codebuild.start_build_and_wait_for_completion(self, **kwargs)[source]

This will start a build of an AWS CodeBuild Project and wait for it to complete. It will return the result of the build.

Parameters
  • self – codebuild client

  • kwargs – these are passed onto the start_build method call

Returns

codebuild_client.batch_get_builds.response[0]

CodeCommit helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.codecommit.list_branches_single_page(self, **kwargs)[source]

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

Parameters
  • self – codecommit client

  • kwargs – these are passed onto the list_branches method call

Returns

codecommit_client.list_branches.response

GuardDuty helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

betterboto.guardduty.list_members_single_page(self, **kwargs)[source]

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

Parameters
  • self – guardduty client

  • kwargs – these are passed onto the list_members method call

Returns

guardduty_client.list_members.response

Cloudwatch logs helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

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

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_delegated_administrators method call

Returns

organizations_client.list_delegated_administrators.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_delegated_services_for_account method call

Returns

organizations_client.list_delegated_services_for_account.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_organizational_units_for_parent method call

Returns

organizations_client.list_organizational_units_for_parent.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_parents method call

Returns

organizations_client.list_parents.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_policies_for_target method call

Returns

organizations_client.list_policies_for_target.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_policies method call

Returns

organizations_client.list_policies.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_roots method call

Returns

organizations_client.list_roots.response

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

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

Parameters
  • self – organizations client

  • kwargs – these are passed onto the list_targets_for_policy method call

Returns

organizations_client.list_targets_for_policy.response

Service Catalog helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the describe_provisioned_product_plan method call

Returns

servicecatalog_client.describe_provisioned_product_plan.response

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_accepted_portfolio_shares method call

Returns

servicecatalog_client.list_accepted_portfolio_shares.response

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_launch_paths method call

Returns

servicecatalog_client.list_launch_paths.response

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_portfolio_access method call

Returns

servicecatalog_client.list_portfolio_access.response

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_portfolios_for_product method call

Returns

servicecatalog_client.list_portfolios_for_product.response

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_principals_for_portfolio_single_page(self, **kwargs)[source]

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_principals_for_portfolio method call

Returns

servicecatalog_client.list_principals_for_portfolio.response

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the list_provisioned_product_plans method call

Returns

servicecatalog_client.list_provisioned_product_plans.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.scan_provisioned_products_single_page(self, **kwargs)[source]

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the scan_provisioned_products method call

Returns

servicecatalog_client.scan_provisioned_products.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

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

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

Parameters
  • self – servicecatalog client

  • kwargs – these are passed onto the search_provisioned_products method call

Returns

servicecatalog_client.search_provisioned_products.response

SSM helpers

What is this?

The following methods are added to clients instantiated using Betterboto:

Methods

exception betterboto.ssm.ParameterVersionNotFoundException[source]
betterboto.ssm.get_parameter_history_single_page(self, **kwargs)[source]

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

Parameters
  • self – ssm client

  • kwargs – these are passed onto the get_parameter_history_single_page method call

Returns

ssm_client.get_parameter_history_single_page.response

betterboto.ssm.put_parameter_and_wait(self, Name, **kwargs)[source]

This will call put_parameter and ensure it has been successfully put by checking it

Parameters
  • self – ssm client

  • Name – The fully qualified name of the parameter that you want to add to the system

  • kwargs – These args are passed through to ssm.put_parameter

Returns

ssm.get_parameter.response