A lightweight library for generating short-term bearer tokens for AWS Bedrock API authentication
Low maintenance activity. Last release 16 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install aws-bedrock-token-generatorAWS Bedrock Token Generator for Python
The AWS Bedrock Token Generator for Python is a lightweight utility library that generates short-term bearer tokens for AWS Bedrock API authentication. This library simplifies the process of creating secure, time-limited tokens that can be used to authenticate with AWS Bedrock services without exposing long-term credentials.
Installation
Using pip
pip install aws-bedrock-token-generator
From source
git clone https://github.com/aws/aws-bedrock-token-generator-python.git
cd aws-bedrock-token-generator-python
pip install -e .
Quick Start
Basic Usage
Create token with no parameters, uses default region, credentials and token expiry time (1 hour)
from aws_bedrock_token_generator import provide_token
token = provide_token() # uses AWS_REGION env var and default credential chain
print(f"Token: {token}")
Create token using EnvProvider credentials provider
from aws_bedrock_token_generator import provide_token
from botocore.credentials import EnvProvider
token = provide_token(region="us-east-1", aws_credentials_provider=EnvProvider())
print(f"Token: {token}")
Create token with AssumeRole credentials provider
from aws_bedrock_token_generator import provide_token
from botocore.credentials import AssumeRoleProvider, CanonicalNameCredentialSourcer, EnvProvider
from botocore.session import Session
from datetime import timedelta
session = Session()
assume_role_provider = AssumeRoleProvider(
profile_name="bearertoken",
load_config=lambda: session.full_config,
client_creator=session.create_client,
credential_sourcer=CanonicalNameCredentialSourcer([EnvProvider()]),
cache={}
)
bearer_token = provide_token(
region="us-east-1",
aws_credentials_provider=assume_role_provider,
expiry=timedelta(seconds=900)
)
print(f"Bearer Token: {bearer_token}")