Deploy a Django Application to Elastic Beanstalk

This is step 4 of 5 of Hands-On Project 4 for Amazon Web Services. In this step, you do final configuration of the Elastic Beanstalk environment, then deploy the application.

Back to Project

Configure Environment Variables

The configuration files in our Django application use the environment variable DJANGO_SETTINGS_MODULE to determine whether to use the development or production configuration at run time. In development, we never provided a value for DJANGO_SETTINGS_MODULE, which caused the application code to default to using the development configuration. In production, we must provide a value, otherwise the production system will also try to use the development settings.

Also, when the application codebase was updated, all secrets (passwords, secret keys, etc.) were removed from the production configuration and in their place, the app was set up to reference environment variables at runtime. To run the production system, we must provide environment variables for these secrets.

We configure Elastic Beanstalk environment variables on the Software page within the Configuration section for our environment.

Click Edit on the Software section, then scroll down to Environment properties. Create environment variables as shown in the following table, then save the configuration.

Here is what the Environment properties section looks like when complete (minus the production password):

Deploy the Application

You deploy the application with the following command from your VS Code virtual environment for the application:

eb deploy

Deployment will start but will take several minutes. While deployment is in progress, the Elastic Beanstalk dashboard shows that deployment is in progress:

The messages in your VS Code terminal will tell you when deployment is complete, and whether it was successful or not:

When deployment is complete, you can click on Go to environment from the environment dashboard. If the application is accessible, the home page will be displayed:

To test that the database connection is working, you can access one of the APIs, such as /store/collections:

The Application is In Production

Congratulations! Your deployment is complete. Or, maybe it’s not working correctly. In the next and final project section, we will talk about troubleshooting your deployment.