Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I address "OSError: mysql_config not found" error during Elastic Beanstalk deployment?

Problem

I am trying to deploy a very simple app on Elastic Beanstalk with a small database backend. I try to install mysqlclient as part of the process outlined by AWS here. However, when I deploy my app, I get the following error from my Elastic Beanstalk logs as it tries to download the package:

Collecting mysqlclient
  Using cached mysqlclient-2.0.1.tar.gz (87 kB)

2020/08/21 20:30:16.419082 [ERROR] An error occurred during execution of command [app-deploy] - [InstallDependency]. Stop running the command. Error: fail to install dependencies with requirements.txt file with error Command /bin/sh -c /var/app/venv/staging-LQM1lest/bin/pip install -r requirements.txt failed with error exit status 1. Stderr:    ERROR: Command errored out with exit status 1:
     command: /var/app/venv/staging-LQM1lest/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bz45889a/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bz45889a/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1tyle8mv
         cwd: /tmp/pip-install-bz45889a/mysqlclient/
    Complete output (12 lines):
    /bin/sh: mysql_config: command not found
    /bin/sh: mariadb_config: command not found
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-bz45889a/mysqlclient/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "/tmp/pip-install-bz45889a/mysqlclient/setup_posix.py", line 65, in get_config
        libs = mysql_config("libs")
      File "/tmp/pip-install-bz45889a/mysqlclient/setup_posix.py", line 31, in mysql_config
        raise OSError("{} not found".format(_mysql_config_path))
    OSError: mysql_config not found

Question

The mysqlclient is the AWS recommended driver to connect to a MySQL database in RDS using Flask or Django. How do I get it installed with Elastic Beanstalk?

Context

I've tried to implement my architecture with either (1) a database within the Elastic Beanstalk environment or (2) a regularly deployed RDS instance outside the Elastic Beanstalk environment. In this case, we're going with option (1).

I can't install mysql-server or other packages using apt-get as suggested here very easily, which is why I hope this isn't labeled as a duplicate. I don't have access to the underlying servers. I attempted to using platform hooks and .ebextensions, but I wasn't able to get that to work. In this post, I'm trying to step back and see if there is another avenue.

like image 898
whoopscheckmate Avatar asked Aug 21 '20 20:08

whoopscheckmate


People also ask

What is the deployment ID for Elastic Beanstalk?

Deployment IDs start at 1 and increment by one with each deployment and instance configuration change. If you enable enhanced health reporting, Elastic Beanstalk displays the deployment ID in both the health console and the EB CLI when it reports instance health status.

How do I install dependencies in Elastic Beanstalk using composer?

When a composer.json file is present, Elastic Beanstalk runs composer.phar install to install dependencies. You can add options to append to the command by setting the composer_options option in the aws:elasticbeanstalk:container:php:phpini namespace. If your application has a large number of dependencies, installing them might take a long time.

How do I set up Elastic Beanstalk with PHP?

Note: The following resolution applies to an Elastic Beanstalk environment with any PHP platform versions. 1. In the root of your application bundle, create a directory named .ebextensions. 2. Create a .ebextensions configuration file, such as .ebextensions / pdo_sqlsrv.config. For example:

How do I deploy a beanstalk application to AWS?

Deploying a new application version 1 Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. 2 In the navigation pane, choose Environments, and then choose the name of your environment from the list. ... 3 Choose Upload and deploy . 4 Use the on-screen form to upload the application source bundle. 5 Choose Deploy .


1 Answers

For Amazon linux 2 you should be able to install it with yum. Thus, you can have in your .ebextensions a file called, e.g. 01_packages.config with the content:

packages: 
    yum:
        MySQL-python: []

You can add further yum dependencies if you require more.

like image 99
Marcin Avatar answered Oct 22 '22 15:10

Marcin