File size: 524 Bytes
d8ad0fd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from urllib.parse import urlparse
import boto3
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
def build_iam_auth(url: str, aws_service: str) -> BotoAWSRequestsAuth:
"""Generates IAM auth keys for a given hostname and service.
This can be directly passed on to the requests library to authenticate the request.
"""
hostname = urlparse(url).hostname
region = boto3.session.Session().region_name
return BotoAWSRequestsAuth(aws_host=hostname, aws_region=region, aws_service=aws_service)
|