Ctrl + K
DocumentationLog inGet started

tessl/pypi-aws-requests-auth

tessl install tessl/pypi-aws-requests-auth@0.4.0

AWS 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%

task.mdevals/scenario-10/

AWS Request Header Builder

Build a utility that generates AWS authentication headers for HTTP requests to AWS services using the AWS Signature Version 4 signing process.

Overview

Create a module that constructs a complete set of AWS authentication headers for a given HTTP request. The utility should accept request details and AWS credentials, then return a dictionary of headers ready to be attached to an HTTP request.

Requirements

Core Functionality

Your implementation should:

  • Accept AWS credentials (access key ID, secret access key, and optional session token)
  • Accept AWS service configuration (service name, region, host)
  • Accept HTTP request details (method, path, query parameters, body)
  • Generate a complete dictionary of AWS authentication headers including:
    • Authorization header with AWS Signature Version 4
    • x-amz-date header with timestamp
    • x-amz-content-sha256 header with payload hash
    • X-Amz-Security-Token header (when session token is provided)
  • Return headers as a dictionary ready to use with any HTTP client

Input Parameters

The header generation function should accept:

  • aws_access_key: AWS access key ID (string)
  • aws_secret_access_key: AWS secret access key (string)
  • aws_host: AWS service endpoint hostname (string)
  • aws_region: AWS region code (string)
  • aws_service: AWS service name (string)
  • method: HTTP method (string, e.g., "GET", "POST")
  • path: Request path (string)
  • params: Query parameters (dict, optional)
  • data: Request body/payload (string or bytes, optional)
  • aws_token: AWS session token (string, optional)

Output Format

Return a dictionary with string keys and string values containing all necessary AWS authentication headers.

Test Cases

  • Given valid AWS credentials and a GET request to "/search?q=test", the function returns a dictionary containing "Authorization", "x-amz-date", and "x-amz-content-sha256" headers @test
  • Given AWS credentials including a session token, the returned headers dictionary includes the "X-Amz-Security-Token" header @test
  • The Authorization header in the returned dictionary starts with "AWS4-HMAC-SHA256" @test

Implementation

@generates

API

def generate_aws_headers(
    aws_access_key: str,
    aws_secret_access_key: str,
    aws_host: str,
    aws_region: str,
    aws_service: str,
    method: str,
    path: str,
    params: dict = None,
    data: str = None,
    aws_token: str = None
) -> dict:
    """
    Generate AWS Signature Version 4 authentication headers.

    Args:
        aws_access_key: AWS access key ID
        aws_secret_access_key: AWS secret access key
        aws_host: AWS service endpoint hostname
        aws_region: AWS region code (e.g., 'us-east-1')
        aws_service: AWS service name (e.g., 'es', 'execute-api')
        method: HTTP method (e.g., 'GET', 'POST')
        path: Request path
        params: Query parameters (optional)
        data: Request body/payload (optional)
        aws_token: AWS session token for temporary credentials (optional)

    Returns:
        Dictionary of AWS authentication headers ready to attach to HTTP request
    """
    pass

Dependencies { .dependencies }

aws-requests-auth { .dependency }

Provides AWS Signature Version 4 authentication for HTTP requests.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/aws-requests-auth@0.4.x
tile.json