我想要一个 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) 与 boto3 一起使用(1.5.15 - 更新到 1.7.1 并没有改变任何东西,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>
.
有没有办法打印错误消息中提到的“规范字符串”?
(任何其他如何解决此问题的想法也值得赞赏)