[英]AWS Authorization In Code - {“message”: “The security token included in the request is invalid.” }
I am trying to invoke an API call in my Lambda function in the form of requests.get(url, auth=auth)
. 我试图以
requests.get(url, auth=auth)
的形式在我的Lambda函数中调用API调用。
I have the url of the API endpoint but I am having issues with the authorization part of it. 我有API端点的url,但我遇到了授权部分的问题。 I imported an equivalent package of Requests-aws4auth and am getting my access key and secret key from Boto3 by following these instructions .
我导入了一个等效的Requests-aws4auth包,并按照这些说明从Boto3获取了我的访问密钥和密钥。
session = boto3.Session()
credentials = session.get_credentials()
credentials = credentials.get_frozen_credentials()
access_key = credentials.access_key
secret_key = credentials.secret_key
auth = AWS4AuthHandler(access_key=access_key, secret_key=secret_key, service_name='execute-api', region_name='us-west-2')
brand_info = requests.get(url, auth=auth).json()
However, brand_info returns: 但是,brand_info返回:
{"message": "The security token included in the request is invalid." }
I'm assuming this is an issue with my access and secret keys, and if that's the case, am I missing any steps to get the correct access / secret key? 我假设这是我的访问和密钥的问题,如果是这样的话,我是否缺少任何获取正确访问/密钥的步骤?
You need to obtain the security token also and pass it on. 您还需要获取安全令牌并将其传递。 You can obtain it as:
你可以获得它:
token = credentials.token
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.