↓ If you do this
↓ I want you to be like this
↓ However, it will be like this
{
"errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
"errorType": "Runtime.ImportModuleError"
}
Work on the client. Just make pip work, zip the one with the external module and put it in from the aws admin console
For example, if you work on amazon linux2 ...
mkdir python/
cd python
yum -y install gcc gcc-c++ kernel-devel python-devel libxslt-devel libffi-devel openssl-devel
yum -y install python-pip
pip install -t ./ requests
cd python
cd ..
zip -r Layer.zip python/
Work in the AWS Management Console. In "Create Layer", insert the Layer.zip file you created earlier and you're done.
Select Layers Click "Add Layer" and the layer you created earlier will appear, so select it.
lambda_function.py
import requests
def lambda_handler(event, context):
#Try throwing a GET on the test site
response = requests.get('https://httpbin.org/get', params={'foo': 'bar'})
return response.json()
Execution result
{
"args": {
"foo": "bar"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.24.0",
"X-Amzn-Trace-Id": "Root=1-5f43a5ad-a04c8100f8c999999e8e2e"
},
"origin": "913.931.998.950",
"url": "https://httpbin.org/get?foo=bar"
}
Recommended Posts