Louis
Louis

Reputation: 1303

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?

Upvotes: 1

Views: 1730

Answers (1)

krishna_mee2004
krishna_mee2004

Reputation: 7366

You need to obtain the security token also and pass it on. You can obtain it as:

token = credentials.token

Upvotes: 4

Related Questions