-1

I am attempting to push a docker build of a python lambda function to AWS with the following command (minus the build args):

docker build --build-arg PROD_DB_HOST="xxx.us-east-1.rds.amazonaws.com"  -t vbam-etf-change-report .

The contents of my requirements.txt file:

mysqlclient==2.0.3
python-dotenv

The contents of my Dockerfile (minus program argument environment variables):

FROM public.ecr.aws/lambda/python:3.8

# Copy function code
COPY ETFChangeReportlLambda.py ${LAMBDA_TASK_ROOT}

# Avoid cache purge by adding requirements first
COPY requirements.txt ${LAMBDA_TASK_ROOT}

RUN pip install --no-cache-dir -r requirements.txt


# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
CMD [ "ETFChangeReportlLambda.handler" ]

The error:

#7 [4/4] RUN pip install --no-cache-dir -r requirements.txt
#7 sha256:1ea7868443d498b5222a02c472168a9dc59c8bdf685330406552a2733ad1f356
#7 0.576 Collecting mysqlclient==2.0.3
#7 0.610   Downloading mysqlclient-2.0.3.tar.gz (88 kB)
#7 0.616      ΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöüΓöü 88.9/88.9 KB 27.3 MB/s eta 0:00:00
#7 0.631   Preparing metadata (setup.py): started
#7 0.746   Preparing metadata (setup.py): finished with status 'error'
#7 0.751   error: subprocess-exited-with-error
#7 0.751
#7 0.751   × python setup.py egg_info did not run successfully.
#7 0.751   Γöé exit code: 1
#7 0.751   Γò░ΓöÇ> [16 lines of output]
#7 0.751       /bin/sh: mysql_config: command not found
#7 0.751       /bin/sh: mariadb_config: command not found
#7 0.751       /bin/sh: mysql_config: command not found
#7 0.751       Traceback (most recent call last):
#7 0.751         File "<string>", line 2, in <module>
#7 0.751         File "<pip-setuptools-caller>", line 34, in <module>
#7 0.751         File "/tmp/pip-install-u5vr3ps6/mysqlclient_7d2089be268641c8a9eb33bc95cf2873/setup.py", line 15, in <module>
#7 0.751           metadata, options = get_config()
#7 0.751         File "/tmp/pip-install-u5vr3ps6/mysqlclient_7d2089be268641c8a9eb33bc95cf2873/setup_posix.py", line 70, in get_config
#7 0.751           libs = mysql_config("libs")
#7 0.751         File "/tmp/pip-install-u5vr3ps6/mysqlclient_7d2089be268641c8a9eb33bc95cf2873/setup_posix.py", line 31, in mysql_config
#7 0.751           raise OSError("{} not found".format(_mysql_config_path))
#7 0.751       OSError: mysql_config not found
#7 0.751       mysql_config --version
#7 0.751       mariadb_config --version
#7 0.751       mysql_config --libs
#7 0.751       [end of output]
#7 0.751
#7 0.751   note: This error originates from a subprocess, and is likely not a problem with pip.
#7 0.753 error: metadata-generation-failed
#7 0.753
#7 0.753 × Encountered error while generating package metadata.
#7 0.753 Γò░ΓöÇ> See above for output.
#7 0.753
#7 0.753 note: This is an issue with the package mentioned above, not pip.
#7 0.753 hint: See above for details.
#7 ERROR: executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1
------
 > [4/4] RUN pip install --no-cache-dir -r requirements.txt:
------
executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1

Is there something I can do to the Dockerfile to help with the "OSError: myssql_config not found) error?

Jens
  • 20,533
  • 11
  • 60
  • 86
jgriffo1
  • 85
  • 8
  • This is just an issue installing the mysqlclient python package in docker. The question really has nothing to do with Lambda or ECR. You are still at the step of building a docker image, you aren't interacting with AWS at this point. – Mark B Mar 28 '22 at 17:01
  • Try looking at some of these https://stackoverflow.com/questions/63464534/error-oserror-mysql-config-not-found-when-installing-python-mysqlclient-with https://stackoverflow.com/questions/7475223/mysql-config-not-found-when-installing-mysqldb-python-interface https://stackoverflow.com/questions/5178292/pip-install-mysql-python-fails-with-environmenterror-mysql-config-not-found – Mark B Mar 28 '22 at 17:02

2 Answers2

1

Faced the same issue recently. You will have to install gcc and mysql-devel on top of your base image. And then add the environment variables as suggested here. So, in the end your docker file should contain:

# Install required development packages and libraries
RUN yum update -y && \
    yum install -y gcc mysql-devel


# Set environment variables for mysqlclient
RUN export MYSQLCLIENT_CFLAGS=`pkg-config mysqlclient --cflags` && \
    export MYSQLCLIENT_LDFLAGS=`pkg-config mysqlclient --libs`

This will install the required packages and set the environment variables required to install mysqlclient.

0

I switched to sqlalchemy and that was a good enough workaround.

jgriffo1
  • 85
  • 8