Skip to content

Auth

Authentication and credential utilities for AWS.


IamAWSRequestsAuth

IamAWSRequestsAuth(
    session=None, service_name="execute-api"
)

Bases: AuthBase

IAM authorizer for signing HTTP requests with AWS SigV4.

This class can be used with the requests library to automatically sign HTTP requests using AWS IAM credentials.

Parameters:

Name Type Description Default
session Optional[Session]

Optional botocore Session object for credentials.

None
service_name str

The AWS service name for signing. Defaults to "execute-api".

'execute-api'
Example
auth = IamAWSRequestsAuth()
response = requests.get(url, auth=auth)

# With custom session and service
auth = IamAWSRequestsAuth(boto3.Session(), 'execute-api')
Source code in src/aibs_informatics_aws_utils/auth.py
32
33
34
35
36
37
38
39
40
41
42
def __init__(self, session: Optional[Session] = None, service_name: str = "execute-api"):
    self.boto3_session = get_session(session)
    credentials = self.boto3_session.get_credentials()
    if not credentials:
        raise ValueError("No AWS credentials found")

    self.sigv4 = SigV4Auth(
        credentials=credentials.get_frozen_credentials(),
        service_name=service_name,
        region_name=self.boto3_session.region_name,
    )