To get the current status and logs of the stack we can use a simple script like the following:
while true; do clear; aws cloudformation describe-stack-events --stack-name stefano; sleep 5; done
Breakdown of the YAML
Breakdown of the YAML
Parameters: The Parameters section defines the variables that will be used in the rest of the YAML. In this case, the variables are InstanceType, KeyName, and ImageId.
Resources: The Resources section defines the AWS resources that will be created. In this case, the resources are a launch configuration, an Auto Scaling group, a load balancer, a target group, and a listener. We are using also in the script in our user data, watchtower to watch for changes in ECR, installing Netdata to monitor and send Pager Duty Alerts on server or network failures, we run specific crons, and installing a tunnel to route private and public traffic through Cloudflare.
LaunchConfiguration: The LaunchConfiguration resource defines the configuration of the EC2 instances that will be created. In this case, the instances will be of type t2.micro, have the Amazon Linux 2 AMI, and be assigned the stefano-us-east-2 keypair.
AutoScalingGroup: The AutoScalingGroup resource defines the Auto Scaling group that will be created. In this case, the Auto Scaling group will have a minimum size of 2, a maximum size of 4, and a desired capacity of 2. The Auto Scaling group will use the MyLaunchConfiguration resource to create new EC2 instances.
LoadBalancer: The LoadBalancer resource defines the load balancer that will be created. In this case, the load balancer will use the MyTargetGroup resource to distribute traffic to the EC2 instances in the Auto Scaling group.
TargetGroup: The TargetGroup resource defines the target group that will be used by the load balancer. In this case, the target group will listen on port 80 and will use the MyLaunchConfiguration resource to determine which EC2 instances to send traffic to.
Listener: The Listener resource defines the listener that will be used by the load balancer. In this case, the listener will listen on port 80 and will forward traffic to the MyTargetGroup resource.
Testing the apps
Add anything, change the code, and create a Pull Request
Wait for an approoval
See the change live on one of the IPs/aws hostnames:
Health Checks
CloudWatch Alarms
Additionally on a separate server we run a simple python check script that periodically run a health check to the 2 AWS EC2 URL endpoints see Debugging section for details: