Creating Python aws elastic beanstalk fails after 300 seconds trying to build wheels for collected packages: opencv-python

I am trying to create an elastic beanstalk from a docker container running a python app. It works fine until I import cv2. Ive tried creating from command line using eb create –timout 30, as well as creating by uploading a zipped source bundle, adding .ebextension/extend-time.config that looks like

option_settings:
    - namespace: aws:elasticbeanstalk:command
      option_name: Timeout
      value: 1000

No matter what I add I continue to get the same error – failed with error Command timed out after 300 seconds. When I build the container locally, it takes close to 20 mins to do the building wheel portion.

My elastic beanstalk logs are below


Collecting Jinja2==2.11.2 (from -r requirements.txt (line 9))
  Downloading https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl (125kB)
Collecting kiwisolver==1.3.1 (from -r requirements.txt (line 10))
  Downloading https://files.pythonhosted.org/packages/d2/46/231de802ade4225b76b96cffe419cf3ce52bbe92e3b092cf12db7d11c207/kiwisolver-1.3.1-cp37-cp37m-manylinux1_x86_64.whl (1.1MB)
Collecting MarkupSafe==1.1.1 (from -r requirements.txt (line 11))
  Downloading https://files.pythonhosted.org/packages/98/7b/ff284bd8c80654e471b769062a9b43cc5d03e7a615048d96f4619df8d420/MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl
Collecting matplotlib==3.3.3 (from -r requirements.txt (line 12))
  Downloading https://files.pythonhosted.org/packages/30/f2/10c822cb0ca5ebec58bd1892187bc3e3db64a867ac26531c6204663fc218/matplotlib-3.3.3-cp37-cp37m-manylinux1_x86_64.whl (11.6MB)
Collecting numpy==1.19.4 (from -r requirements.txt (line 13))
  Downloading https://files.pythonhosted.org/packages/a5/bb/87d668b353848b93baab0a64cddf6408c40717f099539668c3d26fe39f7e/numpy-1.19.4-cp37-cp37m-manylinux2010_x86_64.whl (14.5MB)
Collecting opencv-python==4.4.0.46 (from -r requirements.txt (line 14))
  Downloading https://files.pythonhosted.org/packages/30/46/821920986c7ce5bae5518c1d490e520a9ab4cef51e3e54e35094dadf0d68/opencv-python-4.4.0.46.tar.gz (88.9MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Collecting Pillow==8.0.1 (from -r requirements.txt (line 15))
  Downloading https://files.pythonhosted.org/packages/af/fa/c1302a26d5e1a17fa8e10e43417b6cf038b0648c4b79fcf2302a4a0c5d30/Pillow-8.0.1-cp37-cp37m-manylinux1_x86_64.whl (2.2MB)
Collecting pyparsing==2.4.7 (from -r requirements.txt (line 16))
  Using cached https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl
Collecting python-dateutil==2.8.1 (from -r requirements.txt (line 17))
  Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
Collecting six==1.15.0 (from -r requirements.txt (line 18))
  Using cached https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Collecting virtualenv==20.1.0 (from -r requirements.txt (line 19))
  Downloading https://files.pythonhosted.org/packages/97/f3/c064343ac58d1a54c393a3f66483a29500f644a5918deeb935d28673edd9/virtualenv-20.1.0-py2.py3-none-any.whl (4.9MB)
Collecting waitress==1.4.4 (from -r requirements.txt (line 20))
  Downloading https://files.pythonhosted.org/packages/26/d1/5209fb8c764497a592363c47054436a515b47b8c3e4970ddd7184f088857/waitress-1.4.4-py2.py3-none-any.whl (58kB)
Collecting Werkzeug==1.0.1 (from -r requirements.txt (line 21))
  Downloading https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl (298kB)
Collecting zipp==3.4.0 (from -r requirements.txt (line 22))
  Downloading https://files.pythonhosted.org/packages/41/ad/6a4f1a124b325618a7fb758b885b68ff7b058eec47d9220a12ab38d90b1f/zipp-3.4.0-py3-none-any.whl
Building wheels for collected packages: opencv-python
  Building wheel for opencv-python (PEP 517): started
  Building wheel for opencv-python (PEP 517): still running...
  Building wheel for opencv-python (PEP 517): still running...
  Building wheel for opencv-python (PEP 517): still running...
  Building wheel for opencv-python (PEP 517): still running...

2020/11/25 19:20:34.162347 [ERROR] An error occurred during execution of command [app-deploy] - [Docker Specific Build Application]. Stop running the command. Error: failed to build docker image: Command /bin/sh -c docker build -t aws_beanstalk/staging-app /var/app/staging/ failed with error Command timed out after 300 seconds 

2020/11/25 19:20:34.162364 [INFO] Executing cleanup logic
2020/11/25 19:20:34.172290 [INFO] CommandService Response: {"status":"FAILURE","api_version":"1.0","results":[{"status":"FAILURE","msg":"Engine execution has encountered an error.","returncode":1,"events":[{"msg":"Instance deployment failed to build the Docker image. The deployment failed.","timestamp":1606332034,"severity":"ERROR"},{"msg":"Instance deployment failed. For details, see 'eb-engine.log'.","timestamp":1606332034,"severity":"ERROR"}]}]}

2020/11/25 19:20:34.179178 [INFO] Platform Engine finished execution on command: app-deploy

2020/11/25 19:21:48.013411 [INFO] Starting...
2020/11/25 19:21:48.013472 [INFO] Starting EBPlatform-PlatformEngine
2020/11/25 19:21:48.014192 [INFO] reading event message file
2020/11/25 19:21:48.016750 [INFO] no eb envtier info file found, skip loading env tier info.
2020/11/25 19:21:48.016841 [INFO] Engine received EB command cfn-hup-exec

2020/11/25 19:21:48.147863 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-2:848704378436:stack/awseb-e-pzr9qcmpqm-stack/7dea36d0-2f51-11eb-b892-063ac25cd792 -r AWSEBAutoScalingGroup --region us-east-2
2020/11/25 19:21:49.012276 [INFO] Running command /bin/sh -c /opt/aws/bin/cfn-get-metadata -s arn:aws:cloudformation:us-east-2:848704378436:stack/awseb-e-pzr9qcmpqm-stack/7dea36d0-2f51-11eb-b892-063ac25cd792 -r AWSEBBeanstalkMetadata --region us-east-2
2020/11/25 19:21:49.361111 [INFO] checking whether command tail-log is applicable to this instance...
2020/11/25 19:21:49.361128 [INFO] this command is applicable to the instance, thus instance should execute command
2020/11/25 19:21:49.361132 [INFO] Engine command: (tail-log)

2020/11/25 19:21:49.363040 [INFO] Executing instruction: GetTailLogs
2020/11/25 19:21:49.363049 [INFO] Tail Logs...
2020/11/25 19:21:49.365457 [INFO] Running command /bin/sh -c tail -n 100 /var/log/eb-engine.log

My docker file

# set base image (host OS)
FROM python:3.7.2

# set the working directory in the container
WORKDIR /code

# copy the dependencies file to the working directory
COPY requirements.txt .

# install dependencies
RUN pip install -r requirements.txt

# copy the content of the local src directory to the working directory
COPY src/ .

# command to run on container start
CMD [ "python", "application.py" ]

My requirements.txt

appdirs==1.4.4
click==7.1.2
cycler==0.10.0
distlib==0.3.1
filelock==3.0.12
Flask==1.1.2
importlib-metadata==2.0.0
itsdangerous==1.1.0
Jinja2==2.11.2
kiwisolver==1.3.1
MarkupSafe==1.1.1
matplotlib==3.3.3
numpy==1.19.4
opencv-python==4.4.0.46
Pillow==8.0.1
pyparsing==2.4.7
python-dateutil==2.8.1
six==1.15.0
virtualenv==20.1.0
waitress==1.4.4
Werkzeug==1.0.1
zipp==3.4.0

Source: Docker Questions

LEAVE A COMMENT