简体   繁体   中英

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) .

I have the url of the API endpoint but I am having issues with the authorization part of it. I imported an equivalent package of Requests-aws4auth and am getting my access key and secret key from Boto3 by following these instructions .

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:

{"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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM