I have configured AWS Lambda function to use container image. I have build the image and uploaded it in ECR and using this image to run the lambda function. I'm still facing errors:
[ERROR] PortScannerError: 'nmap program was not found in path. PATH is : /var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin'
Traceback (most recent call last):
File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/app.py", line 36, in <module>
nmScan = nmap.PortScanner()
File "/var/task/nmap/nmap.py", line 132, in __init__
raise PortScannerError(
When I run the script from the container manually it is running fine. While lambda executes this, I get the above error.
using this sample Dockerfile structure to create the Dockerfile:
FROM public.ecr.aws/lambda/python:3.8
# Copy function code
COPY app.py ${LAMBDA_TASK_ROOT}
# Install the function's dependencies using file requirements.txt
# from your project folder.
COPY requirements.txt .
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
RUN yum install -y nmap
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "app.handler" ] ```
Do I need to specify the ENTRYPOINT?
Finally, it worked for me.
In the Lambda function, we can override the value of ENTRYPOINT, CMD, and WORKDIR.
So, I did the override by passing ENTRYPOINT, CMD, and WORKDIR(it defaults to /var/task
for AWS Lambda).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.