[英]Generate the AWS HTTP signature from boto3
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"我正在使用 boto3 尚不支持的AWS Transcribe 流媒体服务,因此要发出 HTTP/2 请求,我需要使用“AWS 签名版本 4”手动设置authorization
header
I've found some example implementation , but I was hoping to just call whatever function boto3/botocore have implemented using the same configuration object.我找到了一些示例实现,但我希望只调用 function boto3/botocore 使用相同配置 object 实现的任何内容。
Something like就像是
session = boto3.Session(...)
auth = session.generate_signature('POST', '/stream-transcription', ...)
Any pointers in that direction?那个方向有什么指示吗?
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.与大多数其他编程语言的 AWS 开发工具包相反, boto3
/ botocore
不提供使用“AWS 签名版本 4”签署任意请求的功能。 However there is at least already an open feature request for that: https://github.com/boto/botocore/issues/1784但是至少已经有一个开放的功能请求: 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.一个是第三方 Python 库aws-requests-auth
,它提供了一个围绕botocore
和requests
的瘦包装器来签署 HTTP 请求。 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 .功能请求中提出的另一种选择是自行实施必要的粘合代码,如以下要点所示:https://gist.github.com/rhboyd/1e01190a6b27ca4ba817bf272d5a5f9a 。
Did you check this SDK?这个SDK你查了吗? Seems very recent but might do what you need.似乎是最近的,但可能会做你需要的。
https://github.com/awslabs/amazon-transcribe-streaming-sdk/tree/master https://github.com/awslabs/amazon-transcribe-streaming-sdk/tree/master
It looks like it handles the signing: https://github.com/awslabs/amazon-transcribe-streaming-sdk/blob/master/amazon_transcribe/signer.py看起来它处理签名: https://github.com/awslabs/amazon-transcribe-streaming-sdk/blob/master/amazon_transcribe/signer.py
I have not tested this, but you can likely accomplish this by following along with with this SigV4 unit test:我没有对此进行测试,但您可以通过遵循此 SigV4 单元测试来完成此操作:
https://github.com/boto/botocore/blob/master/tests/unit/test_auth_sigv4.py https://github.com/boto/botocore/blob/master/tests/unit/test_auth_sigv4.py
Note, this constructs a request using the botocore.awsrequest.AWSRequest
helper.请注意,这会使用botocore.awsrequest.AWSRequest
帮助器构造一个请求。 You'll likely need to dig around to figure out how to send the actual HTTP request (perhaps with httpsession.py )您可能需要深入了解如何发送实际的 HTTP 请求(可能使用httpsession.py )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.