如何打印 aws-requests-auth 发送的规范字符串?

How can I print the Canonical String which aws-requests-auth sends?

我想让一个 lambda 调用另一个区域的 Sagemaker 实例。如果两者都在同一区域,则一切正常。如果不是,我会收到以下错误:

The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

The Canonical String for this request should have been
'POST
/endpoints/foo-endpoint/invocations

host:runtime.sagemaker.us-east-1.amazonaws.com
x-amz-date:20180406T082536Z

host;x-amz-date
1234567890foobarfoobarfoobarboofoobarfoobarfoobarfoobarfoobarfoo'

The String-to-Sign should have been
'AWS4-HMAC-SHA256
20180406T082536Z
20180406/us-east-1/sagemaker/aws4_request
987654321abcdeffoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarf'

我这样使用 aws-requests-auth (0.4.1) with boto3 (1.5.15 - updating to 1.7.1 didn't change anything, changelog):

import requests
from aws_requests_auth.aws_auth import AWSRequestsAuth
auth = AWSRequestsAuth(aws_access_key=config['AWS']['ACCESS_KEY'],
                       aws_secret_access_key=(
                           config['AWS']['SECRET_ACCESS_KEY']),
                       aws_host=config['AWS']['HOST'],
                       aws_region=config['AWS']['REGION'],
                       aws_service=config['AWS']['SERVICE'])

payload = {'foo': 'bar'}
response = requests.post(post_url,
                         data=json.dumps(payload),
                         headers={'content-type': 'application/json'},
                         auth=auth)

打印 auth 只给出 <aws_requests_auth.aws_auth.AWSRequestsAuth object at 0x7f9d00c98390>.

有没有办法打印错误信息中提到的"Canonical String"?

(也欢迎任何其他解决此问题的想法)

A work-around 所问问题:

req = requests.request('POST', 'http://httpbin.org/get')
req.body = b''
req.method = ''
print(auth.get_aws_request_headers(req,
                                   aws_access_key=auth.aws_access_key,
                                   aws_secret_access_key=auth.aws_secret_access_key,
                                   aws_token=auth.aws_token))

不过问题还是没有解决。现在我想知道 auth.get_aws_request_headers 的第一个参数是什么。