Requests – vendored with boto3

on
Nov 10, 2018
in
AWS

This blog content has been deprecated as Amazon announced the removal of the requests library from the botocore packaging. So this content is no longer appropriate.
Requests is a popular HTTP library for Python. The library makes it
easy to call HTTP services and process JSON responses. Boto3 is
the AWS SDK for AWS. When creating a Lambda with the Python programming language, Boto3 is available. There is no need to
package Boto3. Because requests comes vendored with Boto3, it is also available.

Importing vendored requests

Import the following:

import botocore.vendored.requests as requests
from botocore.vendored.requests.auth import HTTPBasicAuth

resp = requests.post(
    'https://httpbin.org', 
    json={'message': 'hello world'}, 
    auth=HTTPBasicAuth('username', 'password'), 
    verify=False, 
    timeout=2)
body = resp.json()
code = resp.status_code

Conclusion

There is no need to package requests or Boto3 when creating a lambda. Both are available for python based lambdas.
The advantage is a small archive and being being able to inline lambdas in a CloudFormation template, which I will
write about in the next blog.

Share this article: Tweet this post / Post on LinkedIn