Deploying a complex Django application to AWS Elastic Beanstalk (EB) provides a scalable, managed environment that handles everything from capacity provisioning to load balancing. On a Mac Mini, the combination of Homebrew and the EB CLI creates a powerful local development station.
This guide covers the full lifecycle of setting up your Mac, preparing your Django project, and launching your environment.
Part 1: Setting up the Mac Mini EnvironmentBefore touching your code, your Mac needs the right tools. We will use Homebrew for the core CLI and Python’s pip for the Elastic Beanstalk specific tools.
1. Install AWS CLI and EB CLIOpen your terminal and run the following commands:
# 1. Update Homebrew
brew update
# 2. Install the standard AWS CLI
brew install awscli
# 3. Install the EB CLI (using the official Python installer for stability)
pip install awsebcli --upgrade --user
2. Configure AWS SSO (Modern Authentication)Most professional environments use IAM Identity Center (SSO). Instead of manual keys, use the managed login:
aws configure sso
-
SSO Start URL: Enter your company portal (e.g.,
https://d-xxxx.awsapps.com/start). -
SSO Region: Choose your account’s home region (e.g.,
us-east-1). - Scopes: Press Enter for the default.
- A browser will open; click Allow, then select your Account and the PowerUserAccess role in your terminal.
Part 2: Preparing the Django ProjectElastic Beanstalk needs specific files to understand how to run your app. Based on a standard modular structure (where settings are in config/settings/), here are the adjustments required.
1. The ProcfileBeanstalk uses a Procfile to know which command starts the web server. Since your project uses Gunicorn, create a file named Procfile in the root:
web: gunicorn config.wsgi:application --bind 0.0.0.0:8000
2. Environment Configuration (.ebextensions)Create a folder named .ebextensions/ in your root. Inside, create django.config:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: config.wsgi:application
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
3. Production SettingsIn config/settings/production.py (or your main settings file), ensure you allow the Beanstalk domain:
import os
ALLOWED_HOSTS = [
'.elasticbeanstalk.com',
'yourcustomdomain.com',
]
# Use environment variables for secrets
SECRET_KEY = os.environ.get('SECRET_KEY')
DEBUG = False
Part 3: Creating and Deploying on AWSNow that the code is ready, we use the EB CLI to provision the infrastructure.
1. Initialize the ApplicationRun this in your project root:
eb init
- Select your Region.
- Select Python as the platform.
- Choose the latest Amazon Linux version (e.g., AL2023).
- Say Yes to SSH if you want to debug the server later.
2. Create the EnvironmentThis command creates the actual EC2 instances and networking:
eb create my-dev-env --single
- The
--singleflag is perfect for dev environments; it launches a Single Instance without a costly Load Balancer.
3. Managing SecretsDon't hardcode passwords. Set them via the CLI:
eb setenv SECRET_KEY="your-secret-key" DEBUG=False
Part 4: Deployment WorkflowOnce the environment is live, updates are simple. Note: Beanstalk only deploys code that has been committed to Git.
- Make changes to your apps or templates.
- Commit your work:
git add .
git commit -m "Updated notification logic"
- Deploy:
eb deploy
- Check Logs: If things go wrong, stream the server logs to your Mac:
eb logs --tail
Summary of Commands| Action | Command |
| --- | --- |
| Login | aws sso login |
| Check Status | eb status |
| Push Code | eb deploy |
| Open App | eb open |
By following this structure, you separate your infrastructure management from your application logic, ensuring that your Mac Mini remains a clean, efficient deployment hub.
Top comments (0)