AWS News Blog
Announcing AWS Elastic Beanstalk support for Python, and seamless database integration
Its a good day to be a Python developer: AWS Elastic Beanstalk now supports Python applications! If youre not familiar with Elastic Beanstalk, its the easiest way to deploy and manage scalable PHP, Java, .NET, and now Python applications on AWS. You simply upload your application, and Elastic Beanstalk automatically handles all of the details associated with deployment including provisioning of Amazon EC2 instances, load balancing, auto scaling, and application health monitoring.
Elastic Beanstalk supports Python applications that run on the familiar Apache HTTP server and WSGI. In other words, you can run any Python applications, including your Django applications, or your Flask applications. Elastic Beanstalk supports a rich set of tools to help you develop faster. You can use eb and Git to quickly develop and deploy from the command line. You can also use the AWS Management Console to manage your application and configuration.
The Python release brings with it many platform improvements to help you get your application up and running more quickly and securely. Here are a few of the highlights below:
Integration with Amazon RDS
Amazon RDS makes it easy to set up, operate, and scale a relational database in the cloud, making it a great fit for scalable web applications running on Elastic Beanstalk.
If your application requires a relational database, Elastic Beanstalk can create an Amazon RDS database instance to use with your application. The RDS database instance is automatically configured to communicate with the Amazon EC2 instances running your application.
A console screenshot showing RDS configuration options when launching a new
AWS Elastic Beanstalk environment.
Once the RDS database instance is provisioned, you can retrieve information about the database from your application using environment variables:
import os
if ‘RDS_HOSTNAME’ in os.environ:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: os.environ[‘RDS_DB_NAME’],
‘USER’: os.environ[‘RDS_USER’],
‘PASSWORD’: os.environ[‘RDS_PASSWORD’],
‘HOST’: os.environ[‘RDS_HOSTNAME’],
‘PORT’: os.environ[‘RDS_PORT’],
}
}
To learn more about using Amazon RDS with Elastic Beanstalk, visit Using Amazon RDS with Python in the Developer Guide.
Customize your Python Environment
You can customize the Python runtime for Elastic Beanstalk using a set of declarative text files within your application. If your application contains a requirements.txt in its top level directory, Elastic Beanstalk will automatically install the dependencies using pip.
Elastic Beanstalk is also introducing a new configuration mechanism that allows you to install packages from yum, run setup scripts, and set environment variables. You simply create a .ebextensions directory inside your application and add a python.config file in it. Elastic Beanstalk loads this configuration file and installs the yum packages, runs any scripts, and then sets environment variables. Here is a sample configuration file that syncs the database for a Django application:
commands:
syncdb:
command: “django-admin.py syncdb –noinput”
leader_only: true
option_settings:
“aws:elasticbeanstalk:application:python:environment”:
DJANGO_SETTINGS_MODULE: “mysite.settings”
“aws:elasticbeanstalk:container:python”:
WSGIPath: “mysite/wsgi.py”
Snapshot your logs
To help debug problems, you can easily take a snapshot of your logs from the AWS Management console. Elastic Beanstalk aggregates the top 100 lines from many different logs, including the Apache error log, to help you squash those bugs.
The snapshot is saved to S3 and is automatically deleted after 15 minutes. Elastic Beanstalk can also automatically rotate the log files to Amazon S3 on an hourly basis so you can analyze traffic patterns and identify issues. To learn more, visit Working with Logs in the Developer Guide.
Support for Django and Flask
Using the customization mechanism above, you can easily deploy and run your Django and Flask applications on Elastic Beanstalk.
- To get started with Django, visit Deploy a Django Application to AWS Elastic Beanstalk in the Developer Guide.
- To get started with Flask, visit Deploy a Flask Application to AWS Elastic Beanstalk in the Developer Guide.
For more information about using Python and Elastic Beanstalk, visit the Developer Guide.
We look forward to hearing about how you put these new features to use!