requests-auth-aws-sigv4 is a Python library that provides an authentication class to integrate AWS Signature Version 4 (SigV4) into the popular `requests` module. It simplifies the process of signing HTTP requests to AWS services, including API Gateway, Elasticsearch, and others, by handling credential retrieval from environment variables, parameters, or `boto3`. The current version is 0.7, with its last release in February 2021, indicating a mature and stable but less frequently updated library.
pip install requests-auth-aws-sigv4Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `requests-auth-aws-sigv4` to sign a request to the AWS Security Token Service (STS) `GetCallerIdentity` API. It shows how to initialize the `AWSSigV4` class with the service and region, explicitly providing credentials or relying on environment variables. The example includes error handling for common `requests` exceptions.
Double-check the service name (e.g., 'es' for Elasticsearch, 's3' for S3, 'execute-api' for API Gateway) and region (e.g., 'us-east-1') against AWS documentation for your specific endpoint.
Synchronize your system's clock using NTP. This library automatically generates the `x-amz-date` header, so clock accuracy is crucial.
Ensure `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables are correctly set, or pass valid `aws_access_key_id` and `aws_secret_access_key` (and optionally `aws_session_token`) to the `AWSSigV4` constructor. If using `boto3` for credentials, ensure it's configured correctly.
Ensure the `Content-Type` header sent in your `requests` call precisely matches what AWS expects and is correctly included in the signature calculation by the library. For JSON, use `application/json`; for form data, use `application/x-www-form-urlencoded`.