How to make an HTTP Request in AWS Lambda using Python

The requests module for Python is very useful in helping simplify HTTP/s requests from Python, but how would you use it in an AWS Lambda script?

While it is not immediately possible to just do a import requests and start using the module, it is possible to import it from the botocore.vendored top-level package.

Python on Lambda exposes a module for common packages called botocore that you can call in any Lambda script.

Using the requests library in Lambda

from botocore.vendored import requests
Code language: Python (python)

Once you have imported the requests library from botocore.vendored, you will be able to make use of all the functionality you are familiar with.

Make the HTTP request

from botocore.vendored import requests response = requests.get("https://ao.gl")
Code language: Python (python)
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Claes
Claes
5 months ago

Please don’t import vendored things in Lambda code in general, and certainly not requests from botocore .vendored, see https://aws.amazon.com/blogs/developer/removing-the-vendored-version-of-requests-from-botocore/