我有一个AWS API网关,我想使用 IAM角色.
I have an AWS API Gateway that I would like to secure using IAM Roles .
我正在寻找一个软件包来帮助我使用Python对其进行访问.我试图避免实施整个版本4签名流程.我确信必须有一些可以使用的库.
I am looking for a package to help me accessing it using Python. I am trying to avoid implementing the entire Version 4 Signing Process. I am sure there must be some library I can use.
我调查了 aws-requests-auth ,但需要"aws_service"来生成签名.我也看了看boto3,但是我找不到任何将身份验证标头添加到常规请求中的方法.
I looked into aws-requests-auth but it requires a "aws_service" to generate the signature. I looked also to boto3 but I am not able to find any way to just add authentication headers to a general request.
推荐答案您可以使用 aws-requests-auth 以使用 execute-api 作为服务名称为您对API网关的请求生成签名.
You can use aws-requests-auth to generate the signature for your request to API Gateway with execute-api as the service name.
import requests from aws_requests_auth.aws_auth import AWSRequestsAuth auth = AWSRequestsAuth(aws_access_key='YOURKEY', aws_secret_access_key='YOURSECRET', aws_host='restapiid.execute-api.us-east-1.amazonaws', aws_region='us-east-1', aws_service='execute-api') headers = {'params': 'ABC'} response = requests.get('restapiid.execute-api.us-east-1.amazonaws/stage/resource_path', auth=auth, headers=headers)更多推荐
通过Python使用IAM角色访问AWS API Gateway
发布评论