This project demonstrates one approach to deploying a web app to AWS. For the sake of simplicity, the web app is a single HTML page served by nginx.
Locally, a Vagrant vm definition provisions a development system. The production environment is an AWS VPC with an autoscaling group setup behind an Elastic Load Balancer. Deploys are accomplished by building an AMI with the current app state and associating the AMI with an autoscaling launch configuration. The autoscaling group handles creating and launching or replacing any existing instances one by one with new instances of the updated AMI.
The app's host system is Ubuntu Trusty based. System configuration and AWS provisioning and deployment are managed via Ansible.
- Ruby >= 2.0
- Python 2.7.9
- Vagrant and Virtualbox
- PhantomJS (via HomeBrew:
brew install phantomjs
) pip install -r requirements.txt
bundle install
Local development is managed via Vagrant's Ansible provisioner.
vagrant up
- provisions a fully working local vm on ip address 192.168.55.2.
Limited Cucumber feature tests are included runnable via:
cucumber
Deploying the current build is accomplished with two commands.
- First, generate a new AMI from the current Ansible build:
AWS_ACCESS_KEY=... AWS_SECRET_KEY=... ansible-playbook bake_ami.yml -e "key_name=*valid key name*"
- Next, deploy the current AMI to a new autoscaling launch configuration. This will either set up a new stack or replace any existing instances one by one with the new build.
AWS_ACCESS_KEY=... AWS_SECRET_KEY=... ansible-playbook deploy_aws.yml -e "key_name=*valid key name*"
./local_dev.yml
playbook responsible for local dev environment../bake_ami.yml
playbook responsible for creating an AWS AMI from the current app build. Saves ami metadata to/vars/current_ami.yml
for use by deploy playbook../deploy_aws.yml
playbook responsible creating a launch config for the AMI described in/vars/current_ami.yml
./roles/nginx/
role responsible for configuring nginx on app host../roles/web_app/
role responsible for deploying web app code../roles/aws_core/
role responsible for basic AWS infrastructure setup.
- Initial Ansible provisioning of the AWS autoscaling group is failing with an error around tags. However, the group is created as expected and subsequent provisions succeed. I'm still investigating this as a potential bug or my own misunderstanding.
Assembled with plenty of sample code and guidance from the following: