Skip to main content

Overview

Crawl through AWS accounts in an organization using master assumed role. You can specify a comma-separated string of account IDs for specific accounts, an Organizational Unit ID to crawl through all accounts therein, or a comma-separated string of account statuses to crawl through matching accounts in the organization.

Crawling Precedence:

  1. Specific accounts

  2. Organizational Unit

  3. All matching accounts in the organization

Usage

Installation:

pip3 install aws_crawler
python3 -m pip install aws_crawler

Example:

import aws_crawler
import boto3
from multithreader import threads
from aws_authenticator import AWSAuthenticator as awsauth
from pprint import pprint as pp


def get_caller_identity(
   account_id: str,
   items: dict
) -> dict:
   """Get AWS STS caller identities from accounts."""
   print(f'Working on {account_id}...')

   try:
      # Get auth credential for each account.
      credentials = aws_crawler.get_credentials(
            items['session'],
            f'arn:aws:iam::{account_id}:role/{items["assumed_role_name"]}',
            items['external_id']
      )

      # Get STS caller identity.
      client = boto3.client(
            'sts',
            aws_access_key_id=credentials['aws_access_key_id'],
            aws_secret_access_key=credentials['aws_secret_access_key'],
            aws_session_token=credentials['aws_session_token'],
            region_name=items['region']
      )
      response = client.get_caller_identity()['UserId']

   except Exception as e:
      response = str(e)

   # Return result.
   return {
      'account_id': account_id,
      'details': response
   }


if __name__ == '__main__':
   # Login to AWS through SSO.
   auth = awsauth(
      sso_url='https://myorg.awsapps.com/start/#',
      sso_role_name='AWSViewOnlyAccess',
      sso_account_id='123456789012'
   )
   session = auth.sso()

   # # Create account list from comma-separated string of IDs.
   # account_ids = aws_crawler.create_account_list(
   #    '123456789012, 234567890123, 345678901234'
   # )
   # Get account list for an Organizational Unit.
   account_ids = aws_crawler.list_ou_accounts(
      session,
      'ou-abc123-asgh39'
   )
   # # Get matching account list for the entire organization.
   # account_ids = aws_crawler.list_accounts(
   #    session,
   #    'ACTIVE,SUSPENDED'
   # )

   # Execute task with multithreading.
   items = {
      'session': session,
      'assumed_role_name': 'MyOrgCrossAccountAccess',
      'external_id': 'lkasf987923ljkf2;lkjf298fj2',
      'region': 'us-east-1'
   }
   results = threads(
      get_caller_identity,
      account_ids,
      items,
      thread_num=5
   )

   # Print results.
   pp(results)

Release files for aws_crawler 1.2.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws_crawler 1.2.8
File Size Uploaded
aws_crawler-1.2.8.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws_crawler 1.2.8
File Interpreter ABI Platform
aws_crawler-1.2.8-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / aws_crawler-1.2.8.tar.gz

Download URL aws_crawler-1.2.8.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
67e511f41557b4c55406346bf0a19cce080423805cbbd466e6d5d9d059b914da
BLAKE2b-256 checksum
How to use checksums
32d8fc7177525dd92a07a0bbaac8afbe7a90e54c496bd8ee7a40bd49a5d6a0cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/5.15.154+

Release files / aws_crawler-1.2.8-py3-none-any.whl

Download URL aws_crawler-1.2.8-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67812a6ffd7672f5807c857587a88edbd0919b92a8f01dd9ce2adbc3d1642a9b
BLAKE2b-256 checksum
How to use checksums
fcbbaedcf710f7f1534a8929d8b7376f0c21efb7ccec57808000ce830a161cc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Linux/5.15.154+

Release history Release notifications | RSS feed

This release

1.2.8 This release

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release 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