tessl install tessl/pypi-aws-requests-auth@0.4.0AWS signature version 4 signing process for the python requests module
Agent Success
Agent success rate when using this tile
84%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.11x
Baseline
Agent success rate without this tile
76%
Build a custom AWS authentication handler that extends the base AWS authentication capabilities to support credential rotation from a configuration file.
Your task is to implement a custom authentication class that:
The credentials configuration file will be in JSON format with the following structure:
{
"aws_access_key_id": "AKIAIOSFODNN7EXAMPLE",
"aws_secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"aws_session_token": "optional-session-token-here",
"region": "us-east-1",
"service": "es"
}The aws_session_token field is optional and may not be present in the configuration file.
Create a class called FileBasedAWSAuth that:
Takes the following parameters during initialization:
config_file_path: Path to the JSON configuration fileaws_host: The AWS service hostname (e.g., "search-example.us-east-1.es.amazonaws.com")Reads credentials from the configuration file every time a request needs to be authenticated (enabling dynamic credential rotation)
Properly handles both scenarios:
aws_session_token is present in the configurationaws_session_token is not present in the configurationWorks as a standard authentication handler with the requests library
When initialized with a valid config file path and AWS host, and the config file contains access key, secret key, region, and service, the class successfully reads and uses these credentials for authentication @test
When the config file includes an aws_session_token, the authentication handler correctly includes the session token in the signed request headers @test
When credentials in the config file are updated between requests, the authentication handler uses the new credentials for subsequent requests @test
@generates
class FileBasedAWSAuth:
"""
AWS authentication handler that reads credentials from a JSON configuration file.
Supports dynamic credential rotation by reading the file before each request.
"""
def __init__(self, config_file_path, aws_host):
"""
Initialize the file-based AWS authentication handler.
Args:
config_file_path: Path to the JSON configuration file containing AWS credentials
aws_host: The AWS service hostname (e.g., "search-example.us-east-1.es.amazonaws.com")
"""
pass
def __call__(self, request):
"""
Called by requests library to authenticate the request.
Args:
request: The prepared request object to be authenticated
Returns:
The authenticated request object with AWS signature headers
"""
passProvides AWS Signature Version 4 authentication for Python requests library.
@satisfied-by