通过Python使用IAM角色访问AWS API Gateway [英] Access AWS API Gateway with IAM roles from Python
问题描述
I have an AWS API Gateway that I would like to secure using IAM Roles .
我正在寻找一个软件包来帮助我使用Python对其进行访问.我试图避免实施整个
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.
推荐答案
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.com',
aws_region='us-east-1',
aws_service='execute-api')
headers = {'params': 'ABC'}
response = requests.get('https://restapiid.execute-api.us-east-1.amazonaws.com/stage/resource_path',
auth=auth, headers=headers)
这篇关于通过Python使用IAM角色访问AWS API Gateway的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!