Skip to main content

A simple decorator to run functions against all AWS accounts in an organization

Project description

botocove

This is a simple decorator for functions to run them against all AWS accounts in an organization. Wrap a function in @cove and inject a session from every AWS account in your org!

Credential requirements are: In the calling account:

  • IAM permissions sts:assumerole, sts:get-caller-identity and organizations:list-accounts
  • From an account that is trusted by other account roles: primarily, an AWS organization master account. In the organization accounts:
  • A trust relationship to the calling account
  • Whatever IAM permisisons your wrapped function is using.

Quickstart

Wrapping a function that is usually passed a boto3 session can now be called with a session from every account required in your AWS organization, assuming a role in each account.

For example:

This function takes a boto3 session and gets the IAM users from an AWS account

import boto3


def get_iam_users(session):
    iam = session.client("iam", region_name="eu-west-1")
    # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.list_users
    all_users = iam.get_paginator("list_users").paginate().build_full_result()

    return all_users

def main():
    session = boto3.session.Session(profile_name="my_dev_account")
    users = get_iam_users(session)
    print(users) # A single account's IAM users

This decorated function is not called with a session from main() and instead has a session injected by the decorator for every account your credentials can assume a role in to. It returns a list of every account that can be accessed and their IAM users.

import boto3
from botocove import cove

# Only required if credentials in the boto3 chain are not suitable
session = boto3.session.Session(profile_name="my_org_master")


@cove(org_session=session)
def get_iam_users(session):
    iam = session.client("iam", region_name="eu-west-1")
    # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.list_users
    all_users = iam.get_paginator("list_users").paginate().build_full_result()

    return all_users

def main():
    all_users = get_iam_users()
    print(all_users) # A list of all responses from IAM's list_users API for every account in the AWS organization

Arguments

@cove: Uses boto3 credential chain to get every AWS account within the organization. Equivialent to: @cove(target_ids=None, ignore_ids=None, rolename=None, org_session=None)

target_ids: Optional[List[str]] A list of AWS accounts as strings to attempt to assume role in to. As default, attempts to use every available account ID in an AWS organization.

ignore_ids: Optional[List[str]] A list of AWS account ID's that will not attempt assumption in to. Allows IDs to be ignored. Works with or without target_ids.

rolename: Optional[str] An IAM role name that will be attempted to assume in all target accounts. Defaults to the AWS default, OrganizationAccountAccessRole

org_session: Optional[Session] A Boto3 Session object. If not provided, defaults to standard boto3 credential chain.

botocove?

It turns out that the Amazon's Boto dolphins are soliditary or small-group animals, unlike the large pods of dolphins in the oceans. This killed my "large group of boto" idea, so the next best idea was where might they all shelter together... a cove!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

botocove-0.1.2.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

botocove-0.1.2-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file botocove-0.1.2.tar.gz.

File metadata

  • Download URL: botocove-0.1.2.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.16-2-MANJARO

File hashes

Hashes for botocove-0.1.2.tar.gz
Algorithm Hash digest
SHA256 17cf4c8df622994b748ec0027d67ea30f2fde515200b1cec9abfc7b80571149f
MD5 4d9230c3f86077a21af3dc2d5e37d712
BLAKE2b-256 43345d0a9aa62be2ac9d2f8c414de3c44252acb7f0594734a1245969afc20018

See more details on using hashes here.

File details

Details for the file botocove-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: botocove-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.8.16-2-MANJARO

File hashes

Hashes for botocove-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bb096858bed34c2f1b168678cad599054537793a968c96eb8764f9a8e4ec4bd0
MD5 6ceb6c04b657e1fa1a0e5a04f40a4619
BLAKE2b-256 cf653be637ab4eeda80b865394d8a7145e8b8fa2506a8b8ebd73db8dbb3a83b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page