Example project demonstrating the usage of AWS-Auth-Handler package for AWS authentication and service interaction.
This project showcases how to use the AWS-Auth-Handler package to:
- Authenticate with AWS using different methods
- List S3 buckets
- List Lambda functions
- Handle AWS credentials securely
- Python 3.13 or higher
- AWS credentials (access key, secret key, or profile)
- AWS-Auth-Handler package installed
AWS-Auth-Handler-PlayBook/
├── app.py # Lambda functions listing example
├── main.py # S3 buckets listing example
├── ai-model.py # Amazon Bedrock with Claude example
├── .env.example # Example environment variables
├── pyproject.toml # Project configuration
└── README.md # This file
-
Clone this repository
-
Install dependencies using one of the following methods:
Using pip:
pip install aws-auth-handler
Using uv (recommended):
# Install uv if you haven't already curl -LsSf https://astral.sh/uv/install.sh | sh # Create virtual environment and install dependencies uv venv source .venv/bin/activate # On Windows use: .venv\Scripts\activate uv pip install -e .
-
Configure AWS credentials:
- Copy
.env.exampleto.env - Add your AWS credentials to
.env:AWS_ACCESS_KEY_ID=your_access_key_here AWS_SECRET_ACCESS_KEY=your_secret_key_here AWS_SESSION_TOKEN=your_session_token_here # Optional AWS_DEFAULT_REGION=us-west-2 # Optional AWS_PROFILE=your_profile_name # Optional
- Copy
Run the S3 bucket listing example:
python main.pyThis will:
- Initialize AWS authentication using credentials from
.env - Display your AWS access key ID
- List all available S3 buckets with creation dates
Run the Lambda functions listing example:
python app.pyThis will:
- Initialize AWS authentication using credentials from
.env - Display your AWS access key ID
- List all Lambda functions in the us-west-2 region with details:
- Function name
- Memory allocation
- Last modified date
Run the AI model example using Amazon Bedrock:
python ai-model.pyThis will:
- Initialize AWS authentication using credentials from
.env - Connect to Amazon Bedrock service
- Use Claude v2 model to generate responses
- Demonstrate text generation with configurable parameters:
- Temperature
- Max tokens
- Top K/P sampling
- Custom prompts
Requirements:
- AWS account with Bedrock access enabled
- Appropriate IAM permissions for Bedrock service
- Region where Bedrock and Claude model is available (default: us-east-1)
The examples demonstrate using AWS-Auth-Handler with .env file authentication, but you can modify the code to use other authentication methods:
# Using named AWS profile
auth = AWSAuthenticator(profile_name='development')
# Using default credentials
auth = AWSAuthenticator()
# Using environment variables directly
auth = AWSAuthenticator() # Will automatically use AWS_* environment variablesBoth examples include error handling for:
- Authentication failures
- AWS service operation failures
- Invalid credentials
Feel free to submit issues, fork the repository, and create pull requests for any improvements.
This project is licensed under the MIT License - see the LICENSE file for details.