AWS SigV4 Authentication with the python requests module
Likely abandoned. No release or commit for years (last release over 5 years ago).
pip install requests-auth-aws-sigv4requests-auth-aws-sigv4
Use AWS signature version 4 Authentication with the python requests module
This package provides an authentication class that can be used with the popular requests package to add the AWS Signature Version 4 authentication information.
The signing code is inspired by the python example provided by AWS.
This package should support any/all AWS API's, including API Gateway API's (execute-api), Elasticsearch clusters, and others. AWS Credentials may be pulled from the environment in an easy and familiar way. The signature is added as a header to the request.
Installation
pip install requests-auth-aws-sigv4
Usage
import requests
from requests_auth_aws_sigv4 import AWSSigV4
r = requests.request('POST', 'https://sts.us-east-1.amazonaws.com',
data=dict(Version='2011-06-15', Action='GetCallerIdentity'),
auth=AWSSigV4('sts'))
print(r.text)
If boto3 is available, it will attempt to use credentials that have been configured for the AWS CLI or SDK's, as documented in Boto3 User Guide: Credentials. Otherwise, if boto3 is not available, credentials must be provided using either environment variables or parameters.
Example using environment variables
Environment variable names are the same as documented for AWS CLI and SDK's.
export AWS_ACCESS_KEY_ID=MYACCESSKEY
export AWS_SECRET_ACCESS_KEY=THISISSECRET
export AWS_SESSION_TOKEN=THISISWHERETHESUPERLONGTOKENGOES
import requests
from requests_auth_aws_sigv4 import AWSSigV4
aws_auth = AWSSigV4('ec2') # If not provided, check for AWS Credentials from Environment Variables
r = requests.request('GET', 'https://ec2.us-east-1.amazonaws.com?Version=2016-11-15&Action=DescribeRegions',
auth=aws_auth)
print(r.text)
Example using parameters
Passing credentials as parameters overrides all other possible sources.
import requests
from requests_auth_aws_sigv4 import AWSSigV4
aws_auth = AWSSigV4('ec2',
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY,
aws_session_token=SESSION_TOKEN,
)
r = requests.request('GET', 'https://ec2.us-east-1.amazonaws.com?Version=2016-11-15&Action=DescribeRegions',
auth=aws_auth)
print(r.text)