Generate the AWS HTTP signature from boto3

Viewed 3208

I am working with the AWS Transcribe streaming service that boto3 does not support yet, so to make HTTP/2 requests, I need to manually setup the authorization header with the "AWS Signature Version 4"

I've found some example implementation, but I was hoping to just call whatever function boto3/botocore have implemented using the same configuration object.

Something like

    session = boto3.Session(...)
    auth = session.generate_signature('POST', '/stream-transcription', ...)

Any pointers in that direction?

3 Answers

Contrary to the AWS SDKs for most other programming languages, boto3/botocore don't offer the functionality to sign arbitrary requests using "AWS Signature Version 4" yet. However there is at least already an open feature request for that: https://github.com/boto/botocore/issues/1784

In this feature request, existing alternatives are discussed as well. One is the third-party Python library aws-requests-auth, which provides a thin wrapper around botocore and requests to sign HTTP-requests. That looks like the following:

import requests
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth

auth = BotoAWSRequestsAuth(aws_host="your-service.domain.tld",
                           aws_region="us-east-1",
                           aws_service="execute-api")
response = requests.get("https://your-service.domain.tld",
                        auth=auth)

Another alternative presented in the feature request is to implement the necessary glue-code on your own, as shown in the following gist: https://gist.github.com/rhboyd/1e01190a6b27ca4ba817bf272d5a5f9a.

Related