This Python sample application uses the Flask framework and Bootstrap to build a simple, scalable customer signup form that is deployed to AWS Elastic Beanstalk. The application stores data in Amazon DynamoDB and publishes notifications to the Amazon Simple Notification Service (SNS) when a customer fills out the form.
This version of the application has been modified so it can be packaged and deployed as a Docker container.
Follow the steps below to deploy the demo application to an Elastic Beanstalk Docker environment. This assumes you have the eb CLI installed, see Getting Set Up with EB Command Line Interface.
git clone https://github.com/awslabs/eb-py-flask-signup.git
cd eb-py-flask-signup
git checkout docker
eb init -p Docker
eb create dev-env
eb openFollow the steps below to deploy the demo application to an Elastic Beanstalk Docker environment. Accept the default settings unless indicated otherwise in the steps below:
- Download the ZIP file from Releases at https://github.com/awslabs/eb-py-flask-signup/releases/tag/docker-v1.0
- Login to the Elastic Beanstalk Management Console
- Click
Create New Applicationand give your app a name and description - Choose 'Docker' in the 'Predefined configuration' dropdown and click
Next - Upload the ZIP file downloaded in Step 1
- Review and launch the application
Packaging this Python application with Docker required us to add two files:
-
Dockerfile- Elastic Beanstalk uses Docker on each of your EC2 Instances to build the Docker Image described by this file:FROM ubuntu:14.04 # Update packages RUN apt-get update -y # Install Python Setuptools RUN apt-get install -y python-setuptools # Install pip RUN easy_install pip # Add and install Python modules ADD requirements.txt /src/requirements.txt RUN cd /src; pip install -r requirements.txt # Bundle app source ADD . /src # Expose EXPOSE 5000 # Run CMD ["python", "/src/application.py"] -
Dockerrun.aws.json- This file describes how to run the Docker Image created by theDockerfile. It indicates that/var/appon the EC2 Instance should be mapped to/var/appon the Docker container, and instructs Elastic Beanstalk to copy log files from/var/eb_logon the container to S3:{ "AWSEBDockerrunVersion": "1", "Volumes": [ { "ContainerDirectory": "/var/app", "HostDirectory": "/var/app" } ], "Logging": "/var/eb_log" }
This app includes a quick 3-part video series on YouTube that will walk you through deploying, using, and customizing the application in 10 minutes or less.
The Part 1 video below describes how to deploy the non-Docker version of this application. To deploy this Dockerized sample, do two things:
- Download the Docker-specific ZIP file from the Releases page described in the video.
- Choose 'Docker' instead of 'Python' in the 'Environment Type' step of the wizard.
- Part 1: http://youtu.be/rsg4YI4mljg
- Part 2: http://youtu.be/IuwfVX52PV8
- Part 3: http://youtu.be/DrRr-JgdgzE
The code includes several Bootstrap themes from bootswatch.com. You can dynamically change the active theme by setting the THEME environment variable in the Elastic Beanstalk Management Console:
Installed themes include:
Similar to themes, you can control Flask debugging by toggling the FLASK_DEBUG env var from the Elastic Beanstalk Management Console.
