Deploying My Web Application in AWS

Prepared by Patrick Chan

This demo is to present how I deploy a simple web application by Ansible in Amazon EC2. The application, web server and the EC2 can be provisioned in a scalable manner by using the Ansible playbooks. The Ansible inventory list is determined by the dynamic inventory mechanism, so you don’t need to maintain the inventory hosts file constantly.

Your public key has been added to 34.215.107.72. You may access to my master server by ssh to ubuntu@34.215.107.72 without entering password.

1. Try to login to ubuntu@34.215.107.72 with your SSH client with your private key


2. Change the working directory to /home/ubuntu/demo


$ cd /home/ubuntu/demo


3. Deploy 2 EC2 instances in AWS by executing Ansible playbook. The number of instances, instance type, volume size can be changed by editing playbooks/deploy-ec2.var and playbooks/deploy-ec2.yml

Executing playbooks/deploy-ec2.yml

$ ansible-playbook playbooks/deploy-ec2.yml

Two new instances are creating:


4. Install and configure Apache web server by executing Ansible playbook.

Executing playbooks/deploy-web.yml

$ ansible-playbook playbooks/deploy-web.yml


5. Install and configure MariaDB by executing Ansible playbook.

Executing playbooks/deploy-mysql.yml

$ ansible-playbook playbooks/deploy-mysql.yml


6. Deploy the web application by executing Ansible playbook.

Executing playbooks/deploy-app.yml

$ ansible-playbook playbooks/deploy-app.yml


7. Query the IP address of the EC2 instances provisioned by executing the following command.

$ ansible all –list-hosts


8. Visit the IP address obtained in Step 6 with your web browser. Test the web application by entering the name, favorite color, cats or dogs. Click Display Data to display the data stored in the database.