0
votes

AWS API Gateway Autherizer lambda is working with warning:

/var/runtime/botocore/vendored/requests/api.py:64: DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'. This dependency was removed from Botocore and will be removed from Lambda after 2020/03/31. https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/. Install the requests package, 'import requests' directly, and use the requests.post() function instead.

I know this can be solved by importing requests package, but I tried if I could solve it using urllib3(default package in boto3). Below is my code

data = {
    'token': access_token,
    'client_id': client_id,
    'client_secret': client_secret,
    'token_type_hint': 'access_token'
}
http = urllib3.PoolManager()

encoded_data = json.dumps(data).encode('utf-8')
introspection = http.request(method='POST',
                             url=INTROSPECTION_ENDPOINT,
                             body=encoded_data,
                             headers={'Content-Type': 'application/x-www-form-urlencoded'}
                             )

after running the code I am getting the following error: {"error_description":"token parameter is required for the introspection endpoint.","error":"invalid_request"}'

but the same is working using requests

data = {
    'token': access_token,
    'client_id': client_id,
    'client_secret': client_secret,
    'token_type_hint': 'access_token'
}

introspection = requests.post(
     url=INTROSPECTION_ENDPOINT,
     data=data,
     headers={
         'Content-Type': 'application/x-www-form-urlencoded'
     }
 )
2

2 Answers

1
votes

Had exactly the same issue in AWS Lambda trying to connect to an OAuth2 endpoint. Took me a while to figure it out, but you need to disable the encode_multipart which is enabled by default.

r = http.request_encode_body('POST', URL, fields=body, headers=headers, encode_multipart=False)
0
votes

Uses request library as I couldn't find a clear answer