Skip to main content

Extract AWS account ID and resource type from an AWS access key ID.

Project description

AWS Access Key ID Utility

A Python module for extracting the AWS Account ID and resource type from an AWS Access Key ID. This tool simplifies the process of decoding AWS Access Key IDs to identify account and resource information programmatically.

AWS Resource Type Prefixes

This table lists various prefixes and their associated AWS resource types. For more details, refer to the AWS IAM User Guide - Unique Identifiers.

Prefix Resource Type
ABIA AWS STS service bearer token
ACCA Context-specific credential
AGPA User group
AIDA IAM user
AIPA Amazon EC2 instance profile
AKIA Access key
ANPA Managed policy
ANVA Version in a managed policy
APKA Public key
AROA Role
ASCA Certificate
ASIA Temporary (AWS STS) access key IDs use this prefix, but are unique only in combination with the secret access key and the session token.

Features

  • Extracts the AWS Account ID from an AWS Access Key ID.
  • Identifies the resource type (e.g., IAM user, role, access key).
  • Lightweight and easy to integrate into your projects.

Installation

Install the package via pip:

pip install aws_access_key_id

Usage

Here’s an example of how to use the module in your Python code:

Extracting AWS Account ID and Resource Type

from aws_access_key_id import get_aws_account_id, get_resource_type

# Example AWS Access Key ID
aws_access_key_id = "AKIAEXAMPLE123456"

# Extract account ID
account_id = get_aws_account_id(aws_access_key_id)
print(f"AWS Account ID: {account_id}")

# Identify resource type
resource_type = get_resource_type(aws_access_key_id[:4])
print(f"Resource Type: {resource_type}")

Functions

get_aws_account_id(aws_access_key_id: str) -> str

  • Input: A valid AWS Access Key ID (e.g., "AKIAEXAMPLE123456").
  • Output: The corresponding 12-digit AWS Account ID.

get_resource_type(prefix: str) -> str

  • Input: The 4-character prefix of the AWS Access Key ID.
  • Output: The resource type (e.g., IAM user, Role, Access Key).

Testing

The package includes a test suite to ensure all functionalities work as expected. To run the tests:

  1. Clone the repository:
git clone https://github.com/yourusername/aws-access-key-id.git
cd aws-access-key-id
  1. Install testing dependencies:
pip install pytest
  1. Run the tests:
pytest tests/

Contributing

Contributions are welcome! Follow these steps to contribute:

  1. Fork the repository.
  2. Create a feature branch:
git checkout -b feature-name
  1. Commit your changes:
git commit -m "Add feature or fix description"
  1. Push the branch to your fork:
git push origin feature-name

5 .Open a pull request.

Development Guidelines

  • Code Style: Follow PEP 8 guidelines.
  • Testing: Add test cases for new features in the tests/ directory.
  • Documentation: Update the README.md file for any major changes.

Project Structure

The repository is organized as follows:

aws_access_key_id/
│
├── aws_access_key_id/        # Module folder
│   ├── __init__.py           # Contains your module code
│
├── tests/                    # Test cases folder
│   ├── test_aws_access_key_id.py  # Unit tests for the module
│
├── LICENSE                   # Project license file (e.g., MIT License)
├── README.md                 # Detailed description and usage documentation
├── setup.py                  # Configuration for building and packaging
├── pyproject.toml            # Build system configuration (PEP 517/518)
├── setup.cfg                 # Optional: Additional build configurations

Explanation

aws_access_key_id/: The core module containing all the functionality.

tests/: Contains test cases to ensure the module works as expected.

LICENSE: The license file for the project (e.g., MIT License).

README.md: Documentation about the project, including installation and usage.

setup.py: Configures the module for distribution and packaging.

pyproject.toml: Specifies the build system and dependencies.

setup.cfg: Optional configurations for packaging tools.

License

This project is licensed under the MIT License.

Feedback

If you have any suggestions, issues, or feature requests, feel free to open an issue on the GitHub repository.

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

aws_access_key_id-1.2.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

aws_access_key_id-1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file aws_access_key_id-1.2.tar.gz.

File metadata

  • Download URL: aws_access_key_id-1.2.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for aws_access_key_id-1.2.tar.gz
Algorithm Hash digest
SHA256 a13375beed8ceb62e36f253283d57f1cfd461e17dbaad505ab877a8453183849
MD5 c5401f38b07c31d53ffb43064d484842
BLAKE2b-256 e953e27fd19d8eb734c3b20453cfa936c75b7ecfda4b8c4121b21d16bb849a6c

See more details on using hashes here.

File details

Details for the file aws_access_key_id-1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_access_key_id-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ba96977dd0c54f6862923e6374f5bf035cd4c9fc72ba1aa7499649f533f9c24a
MD5 64875ef110ab413c713c30f3118c36de
BLAKE2b-256 c1634886985d21009cc2928b75f1f69a9decc9a39a243fa16ac80e9dc4f76da1

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