Lambda deprecation of botocore.vendored.requests - how to resolve

0

My Lambda function is providing the following warning in Cloudwatch:
DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'. This is not a public API in botocore and will be removed in the future. Additionally, this version of requests is out of date. We recommend you install the requests package, 'import requests' directly, and use the requests.post() function instead.

Please note that I use the Lambda console for my function so I can't use the AWS CLI to pip import requests etc.

Having looked up what to do about this (see here: https://aws.amazon.com/blogs/compute/upcoming-changes-to-the-python-sdk-in-aws-lambda/) , there is an option to add a layer to my function using the Lambda console which contains version 1.12.221 of the AWS SDK, which includes the requests module in Botocore.

I have followed the instructions and added the correct version of this SDK to my function based on my region and Python version.

But having added this AWS SDK as a layer, if I try using the code "import requests" in my Python code, I get an error "Unable to import module 'lambda_function': No module named 'requests'"

So please can anyone advise what Python import instruction I am meant to use, if I have added this AWS SDK layer as per the instructions in this AWS blog post?

Many thanks

asked 4 years ago3244 views
2 Answers
0

Hello, I think that you have to import all the botocore library

 from botocore.vendored import requests

I tested the lambda, while using the layer that is mentioned in the web page and without it, and I have different warnings, while testing today:

 /opt/python/botocore/vendored/requests/api.py:67: DeprecationWarning: You are using the post() function from 'botocore.vendored.requests'.  This is not a public API in botocore and will be removed in the future. Additionally, this version of requests is out of date.  We recommend you install the requests package, 'import requests' directly, and use the requests.post() function instead.
  • Without the layer:
 /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.

What I think is that the warning is already in the version that the lambda layer has, for that is showing that warning in that way, and also notice that in the first warning the botocore library is extracted from the /opt/ folder, where according to this AWS page: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html, is the folder where layers are extracted for runtime execution.

I hope this can help you with your problem

Regards

Johnny Valenzuela

answered 4 years ago
0

Hi Johnny
My apologies for having taken so long to respond to you kindly providing feedback to my question from way back in March 22. I thought I would have received an email alert that someone had posted a reply, so I hadn't gone back to check.

So a belated thanks very much for the assistance.

In the end I discovered I needed to download a specific Python 3.6 requests library (arn:aws:lambda:eu-west-1:215029992386:layer:Python36-Requests:1) adding as a layer to my Lambda function. This resolved my problem.

Thanks again
Cliff

answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions