Vendored requests are now removed from botocore.
Consider packaging your Lambda code with requirements.txt using CloudFormation package or SAM CLI packaging functionality.
Answer from adamkonrad on Stack OverflowMy older answer from before vendored
requestsdeprecation: You may be able to leveragerequestsmodule from thebotolibrary without having to install or package your function.Consider this import:
import botocore.vendored.requests as requests
External Rest api call in python with lambda function
[SOLVED][AWS][Python] Call to external APIs from my Lambda function - Serverless Framework - Serverless Forums
amazon web services - How to call an external API or URL ( python code) in AWS lambda function? - Stack Overflow
How to connect Python with HTML on AWS Lambda + API Gateway?
Videos
Vendored requests are now removed from botocore.
Consider packaging your Lambda code with requirements.txt using CloudFormation package or SAM CLI packaging functionality.
My older answer from before vendored
requestsdeprecation: You may be able to leveragerequestsmodule from thebotolibrary without having to install or package your function.Consider this import:
import botocore.vendored.requests as requests
You need to install requests module to your project directory and create a lambda deployment package. See this link for details.
In short, you need to create your index.py file on you development system (PC or mac), install Python & pip on that system; them follow the steps in the doc. To create lambda, choose the 'Upload zip' option instead of the 'Edit inline' one
Scenario : To obtain weather using an third party API
import urllib3
def get_weather():
api = "some url ...."
http = urllib3.PoolManager()
response = http.request('GET',api)
weather_status = json.loads(response.data.decode('utf-8'))
for weather in weather_status:
final_weather = weather["WeatherText"] ## The attribute "WeatherText" will varies depending upon the weather API you are using.
return final_weather
get_weather() # simple function call
Try printing response.data so you can see it in the logs. That might give you a clue. I would also try to switch to Python Requests instead of URLLib3. You may also need to set the Content Type depending on the implementation of the API you're calling.