Lets continue to build the AWS Three Tier Architecture. We have all the pre-requisites for our build now ready from our first page HERE, lets put the application together. Ill break it into the stages as per part1 to explain what we are doing.

The first section defines the variables (created earlier) and creates the AMI from the EC2 instance that you have built and working. In my example I am using US-WEST-1 as my region, so all these initial variables need to be replaced by your versions:



We then wait for the AMI to be created, and once ready we can then move on and create a Launch Instance based on the AMI (so that the Auto Scaling group knows what type of EC2 instance to build from the AMI when called), and also create a Target Group which we will be attaching the EC2 instances to so the Load Balancer knows where to send the requests:


Now we can go ahead and create the Auto Scaling group – this is where we define how many instances of the AMI we need to be running (min/max/desired) which will scale up/down based on CPU usage (by default)


This code has built the Load Balancer and provided us with the public IP of it, we just need to add a listener on to the Load Balancer for port 80 requests and then we are reading to test !


Great ! That’s complete and ready to be tested. Lets run:

VPC ID: vpc-0774b80dcXXXX
Instance ID: i-0617db0bXXXX
Instance AMI: ami-0a4a8e3d3XXXX
Waiting for AMI to be ready (rechecking every 10s)
pending
available
Launch Template: lt-01018ebXXXX
Target Group Id: arn:aws:elasticloadbalancing:us-west-1:24102XXXX:targetgroup/Three-Tier-TG/1fe650e3XXXX
AutoScale Id: arn:aws:autoscaling:us-west-1:24102XXXX:autoScalingGroup:0a1e4467-cb0d-407f-b2b5-46e8b3XXXX:autoScalingGroupName/Three-Tier AS Group
Load Balancer Id: arn:aws:elasticloadbalancing:us-west-1:24102XXXX:loadbalancer/app/threetier/13cad5e03XXXX
Load Balancer DNS: threetier-11302XXXX.us-west-1.elb.amazonaws.com
Load Balancer Listener: arn:aws:elasticloadbalancing:us-west-1:24102XXXX:listener/app/threetier/13cad5e03XXXX/4f63d7d047XXXX
Waiting for Load Balancer to be ready (rechecking every 10s)
provisioning
provisioning
provisioning
provisioning
provisioning
provisioning
provisioning
provisioning
provisioning
provisioning
active
Three Tier Architecture Complete – open DNS for DynamoDB write at:
http://threetier-11302XXXX.us-west-1.elb.amazonaws.com/aws_demo.php

All we do from here is open the ELB web page a few times – which should show an alternating private IP from the VPC subnet range. Then check DynamoDB for the writes to confirm !


Perfect. We have now fully built – via Python and AWS API – a Load Balanced Three Tier Architecture (with one click ! Bring on automation…) Where to from here ? You have the base code and learning – take it from this start and build whatever you need, there is just no limit to the range of solutions you can grow from this simple, scalable and fast design built on AWS.

The “aws_demo.php” file can be downloaded from HERE

The “AWS 3 tier arch.py” file can be downloaded from HERE

To view all of the sections we have built in this series via the GUI, navigate to:
EC2 -> Instances
EC2 -> Launch Templates
EC2 -> AMIs
EC2 -> Load Balancers
EC2 -> Target Groups
EC2 -> Auto Scaling Groups

AWS Three Tier Architecture with Python – part2
Tagged on:                         

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.