I need to call external API and print the output as JSON. I'm using AWS Lambda function to execute this code sample in serverless environment. Following is the code and its return error as
Error message "errorMessage": "Unable to import module 'lambda_function': No module named 'requests'", "errorType": "Runtime.ImportModuleError", "requestId": "399d0ea2-6713-4714-90ee-1b8e9924af13", "stackTrace": []
Code Sample
import json
import boto3
import requests
from botocore.vendored import requests
BASE_URL = 'https://fakestoreapi.com'
query_params = {
"limit": 1
}
response = requests.get(f"{BASE_URL}/products", params=query_params)
print(response.json())
Some of the post suggested solution as use Python 3.7. I'm using 3.9. Is this 'requests' module not available in Python 3.9? How to use this in Python 3.9? Some of the post suggested to "pip3 install -t python requests" . I'm using Lambda function inside AWS. How to execute this command if require?