Skip to main content

A decorator to run boto3 functions against an AWS 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


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.

@cove
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_org_master")
    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

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.1.tar.gz (4.6 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.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: botocove-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for botocove-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fe50bfcefb8c845857878d34cf38ce1c4ad1151c8aa581de441f5b22fa888854
MD5 d4e6839c7726e1f73f7e321836be8dc4
BLAKE2b-256 7d9694480344c5f23152a629bd13385cc5712c48e2afaebb05e9efaeb0c3a101

See more details on using hashes here.

File details

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

File metadata

  • Download URL: botocove-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for botocove-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4341a39316269175a0b512a81ef1dc41e5e3f932cb34addd39dd76f5174d5aaf
MD5 c62f2f55fcdd9b8237490a06da0ba129
BLAKE2b-256 59260079b16dd744db447d645bba585dccf67a1c61e3f3380c266948546dffa1

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