Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

An set of opinioned (but flexible) Python libraries for querying and transforming data from various AWS APIs, as well as a CLI interface.

This is in early development.

Installation

Using pip should work on any system with at least Python 3.9:

$ pip install aws-data-tools

By default, the CLI is not installed. To include it, you can specify it as an extra:

$ pip install aws-data-tools[cli]

Usage

There are currently 4 main components of the package: helpers for working with AWS session and APIs, data models for API data types, builders to query AWS APIs and perform deserialization and ETL operations of raw data, and a CLI tool to further abstract some of these operations.

API Client

The APIClient class wraps the initialization of a boto3 session and a low-level client for a named service. It contains a single api() function that takes the name of an API operation and any necessary request data as kwargs.

It supports automatic pagination of any API operations that support it. The pagination config is set to {'MaxItems': 500} by default, but a pagination_config dict can be passed for any desired customizations.

When initializing the class, it will create a session and a client.

from aws_data_tools.client import APIClient

client = APIClient("organizations")
org = client.api("describe_organization").get("organization")
roots = client.api("list_roots")
ous = client.api("list_organizational_units_for_parent", parent_id="r-abcd").get(
    "organizational_units"
)

Note that, generally, any list operations will return a list with no further filtering required, while describe calls will have the data keyed under the name of the object being described. For example, describing an organization returns the relavant data under an organization key.

Furthermore, you may notice above that API operations and their corresponding arguments support snake_case format. Arguments can also be passed in the standard PascalCase format that the APIs utilize. Any returned data has any keys converted to snake_case.

The raw boto3 session is available as the session field, and the raw, low-level client is available as the client field.

Data Models

The models package contains a collection of opinionated models implemented as data classes. There is a package for each available service. Each one is named after the service that would be passed when creating a boto3 client using boto3.client('service_name').

Most data types used with the Organizations APIs are supported. The top-level Organization class is the most useful, as it also acts as a container for all other related data in the organization.

The following data types and operations are currently not supported:

  • Viewing organization handshakes (for creating and accepting account invitations)
  • Viewing the status of accounts creations
  • Viewing organization integrations with AWS services (for org-wide implementations of things like CloudTrail, Config, etc.)
  • Viewing delegated accounts and services
  • Any operations that are not read-only

All other data types are supported.

from aws_data_tools.client import APIClient
from aws_data_tools.models.organizations import Organization

client = APIClient("organizations")
data = client.api("describe_organization").get("organization")
org = Organization(**data)
org.as_json()

View the package for the full list of models.

Builders

While it is possible to directly utilize and interact with the data models, probably the largest benefit is the builders package. It abstracts any API operations and data transformations required to build data models. The models can then be serialized to dicts, as well as JSON or YAML strings.

A full model of an AWS Organization can be constructed using the OrganizationDataBuilder class. It handles recursing the organizational tree and populating any relational data between the various nodes, e.g., parent-child relationships between an OU and an account.

The simplest example pulls all supported organizational data and creates the related data models:

from aws_data_tools.builders.organizations import OrganizationDataBuilder as odb

org = odb(init_all=True)

Note that this makes many API calls to get this data. For example, every OU, policy, and account requires an API call to pull any associated tags, so every node requires at least n+3 API calls. Parallel operations are not supported, so everything runs serially.

To get a sense of the number of API calls required to populate organization data, an organization with 50 OUs, 5 policies, 200 accounts, and with all policy types activated requires 316 API calls! That's why this library was created.

For more control over the process, you can init each set of components as desired:

from aws_data_tools.builders.organizations import OrganizationDataBuilder as odb

org = odb()
org.init_connection()
org.init_organization()
org.init_root()
org.init_policies()
org.init_policy_tags()
org.init_ous()
org.init_ou_tags()
org.init_accounts()
org.init_account_tags()
org.init_policy_targets()
org.init_effective_policies()

CLI

As noted above, the CLI is an optional component that can be installed using pip's bracket notation for extras:

$ pip install aws-data-tools[cli]

With no arguments or flags, help content is displayed by default. You can also pass the --help flag for the help content of any commands or subcommands.

$ awsdata
Usage: awsdata [OPTIONS] COMMAND [ARGS]...

  A command-line tool to interact with data from AWS APIs

Options:
  --version    Show the version and exit.
  -d, --debug  Enable debug mode
  -h, --help   Show this message and exit.

Commands:
  organization  Interact with data from AWS Organizations APIs

Here is how to dump a JSON representation of an AWS Organization to stdout:

The organization subcommand allows dumping organization data to a file or to stdout:

$ awsdata organization dump-json --format json
Usage: awsdata organization dump-json [OPTIONS]

  Dump a JSON representation of the organization

Options:
  --no-accounts             Exclude account data from the model
  --no-policies             Exclude policy data from the model
  -f, --format [JSON|YAML]  The output format for the data
  -o, --out-file TEXT       File path to write data instead of stdout
  -h, --help                Show this message and exit.

Roadmap

The goal of this package is to provide consistent, enriched schemas for data from both raw API calls and data from logged events. We should also be able to unwrap and parse data from messaging and streaming services like SNS, Kinesis, and EventBridge.

Here are some examples:

  • Query Organizations APIs to build consistent, denormalized models of organizations
  • Validate and enrich data from CloudTrail log events
  • Parse S3 and ELB access logs into JSON

This initial release only contains support for managing data from AWS Organizations APIs.

The following table shows what kinds of things may be supported in the future:

Library Name Description Data Type Data Sources Supported
organizations Organization and OU hierarchy, policies, and accounts API Organizations APIs
cloudtrail Service API calls recorded by CloudTrail Log S3 / SNS / SQS / CloudWatch Logs / Kinesis / Kinesis Firehose
s3 Access logs for S3 buckets Log S3 / SNS / SQS
elb Access logs from Classic, Application, and Network Load Balancers Log S3 / SNS / SQS
vpc_flow Traffic logs from VPCs Log S3 / CloudWatch Logs / Kinesis / Kinesis Firehose
config Resource state change events from AWS Config Log S3 / SNS / SQS
firehose Audit logs for Firehose delivery streams Log CloudWatch Logs / Kinesis / Kinesis Firehose
ecs Container state change events Log CloudWatch Events / EventBridge
ecr Repository events for stored images Log CloudWatch Events / EventBridge

References:

Contributing

View the Contributing Guide to learn about giving back.

Download files

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

Source Distribution

aws_data_tools-0.1.0b1.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

aws_data_tools-0.1.0b1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file aws_data_tools-0.1.0b1.tar.gz.

File metadata

  • Download URL: aws_data_tools-0.1.0b1.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.2 Darwin/19.6.0

File hashes

Hashes for aws_data_tools-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 e9dfd88760677cead14870376a4910c5e09f8c03543e2a658477abd3076ccdab
MD5 f60aefcd017fcd04a9cac06444b4b606
BLAKE2b-256 a24f763395248bc5a78cae56a50ffeaccca4d1e5b75adb2294fa1256c487a0d1

See more details on using hashes here.

File details

Details for the file aws_data_tools-0.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: aws_data_tools-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.2 Darwin/19.6.0

File hashes

Hashes for aws_data_tools-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 278575c8975f5d9b72cd45525d48a71f202946954fe79d513a3f90c45ef8ecac
MD5 3417d93be88792331456ff188f385a84
BLAKE2b-256 c0ed6cd6158966f596f7832b080f93ee9f0e9464959f1b65082bb363b94249d0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0b1 This release

2 files

0.1.0a4

2 files

0.1.0a1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page