AWS Bedrock Token Generator
raw JSON → 1.1.0 verified Fri May 01 auth: no python
A lightweight library for generating short-term bearer tokens for AWS Bedrock API authentication. Version 1.1.0, supports Python >=3.7. Released by AWS. Used to obtain tokens for invoking Bedrock without managing long-lived credentials.
pip install aws-bedrock-token-generator Common errors
error ImportError: No module named 'aws_bedrock_token_generator' ↓
cause Installed the package with hyphens but importing with hyphens is invalid.
fix
pip install aws-bedrock-token-generator; then use
import aws_bedrock_token_generator (underscores). error botocore.exceptions.NoCredentialsError: Unable to locate credentials ↓
cause AWS credentials not configured.
fix
Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables or configure ~/.aws/credentials.
error AttributeError: module 'aws_bedrock_token_generator' has no attribute 'get_bearer_token' ↓
cause Using an older version where the function was named differently or not imported at package level.
fix
Upgrade to >=1.0.0 or import
from aws_bedrock_token_generator.core import get_bearer_token. Warnings
gotcha The token expires quickly (default 1 hour). Do not cache tokens without respecting the expiry. Re-generate for each session or use the BedrockTokenGenerator class with caching built-in. ↓
fix Use BedrockTokenGenerator class or implement your own caching with token expiry check.
deprecated The low-level `get_bearer_token` function is deprecated in favor of the `BedrockTokenGenerator` class which provides better caching and refresh logic. ↓
fix Use `from aws_bedrock_token_generator import BedrockTokenGenerator` and instantiate `generator = BedrockTokenGenerator()` then call `generator.get_token()`.
gotcha The library requires boto3 and AWS credentials. If credentials are missing, it raises a `CredentialsError` (from boto3). ↓
fix Ensure AWS credentials are set via environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) or a default profile.
Imports
- get_bearer_token wrong
from bedrock_token_generator import get_bearer_tokencorrectfrom aws_bedrock_token_generator import get_bearer_token - BedrockTokenGenerator wrong
from aws_bedrock_token_generator.generator import BedrockTokenGeneratorcorrectfrom aws_bedrock_token_generator import BedrockTokenGenerator
Quickstart
from aws_bedrock_token_generator import get_bearer_token
import os
# AWS credentials must be configured (via env vars or boto3 session)
token = get_bearer_token()
# token is a dict: {'access_token': '...', 'expires_in': 3600}
print(token['access_token'])