通过Python使用IAM角色访问AWS API Gateway

编程入门 行业动态 更新时间:2024-10-27 08:37:46
本文介绍了通过Python使用IAM角色访问AWS API Gateway的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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

本文发布于:2023-10-23 00:26:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角色   IAM   Python   Gateway   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!