Published on

How to Deploy a Python App to AWS Elastic Beanstalk in 2026

To deploy a Python application to AWS Elastic Beanstalk (a service that automatically handles the deployment, management, and scaling of web applications), you can move from local code to a live URL in under 15 minutes using the EB CLI (Elastic Beanstalk Command Line Interface). By creating a simple configuration file and running the eb create command, AWS provisions the necessary servers, load balancers, and security groups for you. This approach allows you to host production-ready apps without manually configuring complex cloud infrastructure.

What do you need before starting?

Before you touch the cloud, you need a few essential tools installed on your computer. We've found that keeping your local environment identical to your server environment prevents 90% of deployment errors.

  • Python 3.14+: The latest stable version of the programming language used to write your app.
  • AWS Account: A registered account with Amazon Web Services (you can use the Free Tier for this tutorial).
  • AWS CLI: A tool that lets you interact with AWS services using text commands in your terminal.
  • EB CLI: A specific set of commands designed to manage Elastic Beanstalk environments easily.
  • Git: A version control system (a tool that tracks changes to your code) which Elastic Beanstalk uses to package your files.

How do you prepare your Python code for AWS?

AWS needs to know exactly which libraries your app uses and how to start the web server. You provide this information using two specific files in your project folder.

Step 1: Create a virtual environment A virtual environment (an isolated folder that keeps your project's tools separate from other projects) ensures your app doesn't break when you update your computer. Open your terminal and run:

# Create the environment folder named 'venv'
python -m venv venv

# Activate it (Windows)
venv\Scripts\activate

# Activate it (Mac/Linux)
source venv/bin/activate

Step 2: Install your web framework For this example, you'll use Flask (a lightweight framework for building web applications). You should also install gunicorn (a production-grade web server that handles multiple requests at once).

# Install the necessary libraries
pip install flask gunicorn

Step 3: Create the requirements file AWS looks for a file called requirements.txt to know what to install on the cloud server. Run this command to generate it automatically:

# Save a list of installed tools to a file
pip freeze > requirements.txt

Step 4: Create your application file Create a file named application.py. Elastic Beanstalk looks for this specific filename by default to find your code.

from flask import Flask

# AWS looks for a variable named 'application' by default
application = Flask(__name__)

@application.route("/")
def hello_world():
    # This is what users see when they visit your URL
    return "Hello! My Python app is live on Elastic Beanstalk."

if __name__ == "__main__":
    # Run the app locally for testing
    application.run()

How do you configure the Elastic Beanstalk environment?

Now that your code is ready, you need to tell AWS how to handle it. This is done through the EB CLI, which initializes your project settings.

Step 1: Initialize your project Run the following command in your terminal. It will ask you a series of questions about your preferred region (the physical location of the data center) and platform.

eb init -p python-3.14 my-python-app

Step 2: Select your credentials If this is your first time, the tool will ask for your Access Key ID and Secret Access Key. You can find these in the IAM (Identity and Access Management) section of your AWS Console.

Step 3: Test locally Before going live, it's a good idea to see if the EB settings work on your machine. Run eb local run to verify the app starts without errors.

How do you create the actual live environment?

Creating the environment is the step where AWS actually rents the servers for you. This process typically takes about 5 to 10 minutes to finish.

Step 1: Run the create command Type eb create dev-env into your terminal. This command tells AWS to build a new environment named "dev-env" and upload your code.

Step 2: Monitor the progress You will see a stream of text in your terminal. AWS is currently creating a Security Group (a virtual firewall) and an EC2 instance (a virtual computer in the cloud).

Step 3: Check the status Wait until the terminal says "Environment details for: dev-env" and the status is "Green." This color means your application is healthy and running correctly.

How do you view and update your live application?

Once the deployment finishes, you don't need to hunt for a URL in the AWS dashboard. The CLI provides a direct shortcut to see your work.

Run eb open in your terminal. This command automatically opens your default web browser to the public URL of your application.

If you make changes to your code later, the process is very simple. Save your files, use Git to commit the changes, and then run eb deploy.

The eb deploy command bundles your updated code and sends it to the existing servers. This ensures your users always see the latest version of your app without any downtime.

How do you integrate AI models like GPT-5 or Claude 4.5?

Modern Python apps often act as a bridge between users and advanced AI models. To add intelligence to your Elastic Beanstalk app, you would use an API (a way for two programs to talk to each other).

You can install the official libraries for Claude Sonnet 4 or GPT-5 using pip. Once installed, you add your API key to the Elastic Beanstalk Environment Properties.

Environment Properties are secret variables stored in the AWS cloud instead of your code. This keeps your sensitive keys safe from hackers while allowing your app to generate text or analyze data.

What are the common gotchas to watch out for?

It is normal to run into a few hurdles during your first deployment. Most beginners encounter issues with naming or missing dependencies.

  • The "Module Not Found" Error: This usually happens because a library was not added to requirements.txt. Always run pip freeze > requirements.txt after installing new tools.
  • The 502 Bad Gateway Error: This often means your code crashed during startup. Check your logs by running eb logs to see the specific Python error message.
  • Incorrect Variable Name: Elastic Beanstalk expects your Flask object to be named application. If you name it app, the server won't know how to start your program.

Next Steps

Now that your app is live, you can explore more advanced features like connecting a database. You might also want to set up a custom domain name so users can visit "yourname.com" instead of the long AWS URL.

Try adding a new route to your application.py file and deploying it. This will help you get comfortable with the update cycle.

For more details on Python settings, visit the official Python documentation.


Read the Deploy Documentation