-1

i created a simple lambda function like calling api url and i have import requests library in my lambda function and i downloaded requests library in my local machine with command (pip3 install requests -t ) and zipped the folder and added as a layer in my lambda function but am getting below error.

Here my lambda function:

import json
from config import base_url
import requests

def lambda_handler(event, context):
    res = requests.get(url=base_url+'todos/1')
    return {
        'statusCode': res.statusCode,
        'body': res.json()
    }

config.py file:

base_url="https://jsonplaceholder.typicode.com/"

Response:

{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
  "errorType": "Runtime.ImportModuleError",
  "requestId": "486a7cda-4162-4809-bcb8-cb12bf640e60",
  "stackTrace": []
}
0

1 Answer 1

0

If you can't create your own requests layer, please use publicily avaiabile layers witch work out of the box. For example, request is provided by Klayers layers.

In us-east-1, for python 3.11, the layer arn is:

arn:aws:lambda:sa-east-1:770693421928:layer:Klayers-p311-requests:1

You can find corresponding arns for other python versions and regions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.