Search code examples
pythonamazon-web-servicesflaskamazon-ec2amazon-elastic-beanstalk

How to deploy to AWS Elastic Beanstalk using Python 3.11 64bit Amazon Linux 2023


I am trying to deploy a simple Flask app to Elastic beanstalk. I am able to deploy the sample version. However, I am currently struggling to deploy my own. My Python app is already named application.py and changed flask name in the code to "application" in the code. Inside my .ebextension files are the following:

postgres.config:

packages:
    yum:
        mariadb-devel: []
        postgresql-devel: []

(edit: removed mariadb-devel. now says postgres is not available to install. More info below)

python.config:

commands:
  01_update_pip:
    command: "pip install --upgrade pip setuptools"

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: application.py

I am using the AWS website for deployment. I am semi-new and still figuring it out. My directory looks like this:

  • server (root)
    • .ebextensions - postgres.config - python.config
    • application.py
    • requirements.txt
  • venv

in the logs some noticeable things:

[INFO] Error occurred during build: Yum does not have postgresql-devel available for installation
[ERROR] An error occurred during execution of command [app-deploy] - [PreBuildEbExtension]
[WARN]could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size

I've tried running another command that seems to at least deploy in Amazon Linux 2 but with a bad gateway error. Sadly, I do not remember it any more. Plus, I would prefer if possible to stick to the newest version. If it's easier attempting it in a different way then that's OK.

On Amazon Linux 2 (assuming name is Application.py):

commands:
  01_update_pip:
    command: "pip install --upgrade pip setuptools"

option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: Application:application

Solution

  • The documents for Elastic Beanstalk is not updated for AL2023 and still uses AL2, so don't just follow elastic beanstalk docs if you want to use AL2023.

    I don't think they have postgresql-devel package for AL2023, based on this link for installed package list. Also, they changed package manager from yum to dnf, even though yum should still work, I would recommend changing yum to dnf in your file.

    If you can, it is best if you ssh into deployed elastic beanstalk instance and type "dnf search" for the exact name of package you search for. As in the link here.