httpx-auth-awssigv4
![codecov](https://codecov.io/gh/mmuppidi/httpx-auth-awssigv4/branch/master/graphs/badge.svg)
This package provides utilities to add AWS Signature V4 authentication infrormation to calls made by python httpx library.
Installation
pip install httpx-auth-awssigv4
Usage
Basic Usage
This library has primarily been developed to help add authentication support to httpx library while making calls to
REST API deployed using AWS API Gateway service. Will be extended in future to help with calling AWS services.
import httpx
from httpx_auth_awssigv4 import Sigv4Auth
auth = Sigv4Auth(
access_key="AWS_ACCESS_KEY_ID",
secret_key="AWS_SECRET_ACCESS_KEY",
service="execute-api",
region="us-east-1"
)
response = httpx.get(
url="https://<API ID>.execute-api.<Region>.amazonaws.com/prod/detials",
params={"username": "tstark"},
auth=auth
)
response = httpx.get(
url="https://<API ID>.execute-api.<Region>.amazonaws.com/prod/details",
params={"username": "tstark"},
json={"mission": "avengers"},
auth=auth
)
With STS credentials
Sigv4Auth
can be used with temporary credentials generated with tools like aws-sso-util.
import boto3
from httpx_auth_awssigv4 import Sigv4Auth
credentials = boto3.Session(profile_name="<profile>").get_credentials()
auth = Sigv4Auth(
access_key=credentials.access_key,
secret_key=credentials.secret_key,
token=credentials.token
service="execute-api",
region="us-east-1"
)
Sigv4Auth
can also be used with temporary credentials from AWS STS.
import boto3
from httpx_auth_awssigv4 import Sigv4Auth
ROLE_ARN="arn:aws:iam::<ACCOUNT ID>:role/<ROLE NAME"
credentials = boto3.client('sts').assume_role(
RoleArn=ROLE_ARN,
RoleSessionName="httpxcall"
)["Credentials"]
auth = Sigv4Auth(
access_key=credentials["AccessKeyId"],
secret_key=credentials["SecretAccessKey"],
token=credentials["SessionToken"]
service="execute-api",
region="us-east-1"
)
ToDo
- Add examples on usage along with API backend deployment instructions.
- Test the library with AWS services and add integration tests.
Credits