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.3.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.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aws_access_key_id-1.3.tar.gz
Algorithm Hash digest
SHA256 e6adba44884dc09433ec27e88abd199a3dc1891d93dc74f479071355cd5f19f3
MD5 18552bc49fc6f632732682ef9598bff0
BLAKE2b-256 8f9614507101b756c1344d2ec47be7cb023224a24e00e4199b0c94ef23b8ed95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aws_access_key_id-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 19092b919d125c0d6522d5cad06ed1a0ebf7c26c0216518fc55e7ca38439a9c3
MD5 8e8aba0aa014a00648ecc4771007f56f
BLAKE2b-256 cc643266c37d48eda030ee0231a376d79e1521abb3240673fa3a7439ee99d925

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