Highly available EC2 instance
Three ways to keep a single EC2 instance and its Elastic IP available - a standby instance with a CloudWatch alarm and Lambda, an Auto Scaling group of one across AZs, and the same with EBS data carried over by snapshots and lifecycle hooks.
Some apps can only run as one instance (a license server, a legacy app) and are reached at one public IP. How does it stay available?
A standby instance and Lambda
- Users reach the public instance through an Elastic IP.
- A CloudWatch alarm (on a metric or status check) or an EventBridge rule watches it.
- On failure it invokes Lambda, which starts the standby instance and attaches the Elastic IP to it.
An Auto Scaling group of one
- An ASG with min 1, max 1, desired 1, across at least 2 AZs.
- If the instance fails, the ASG launches a replacement, possibly in the other AZ.
- The instance's user data attaches the Elastic IP, found by tag, when it boots.
- The instance needs an IAM role that allows the API calls to attach the Elastic IP.
Keeping the EBS data
An EBS volume is tied to its AZ, so the replacement in another AZ can't just reattach it:
- An ASG terminate lifecycle hook takes an EBS snapshot (with tags) before the instance goes away.
- An ASG launch lifecycle hook creates a new volume from that snapshot in the new AZ and attaches it to the replacement.
Not in the course slides
For hardware failures within one AZ, EC2 automatic instance recovery (simplified automatic recovery is on by default for supported instances, or a CloudWatch alarm action) moves the instance to new hardware and keeps its instance ID, private IPs, Elastic IP and EBS volumes. It doesn't help if the AZ fails. See EC2 instance recovery.
Real-world examples
- A license server that clients reach at a fixed IP runs in an ASG of one across two AZs; its user data reattaches the Elastic IP tagged
license-server, and its config lives on EFS so no snapshot dance is needed.
Exam tips
- "Single instance, must survive an AZ failure, fixed public IP" → ASG min/max/desired 1 across 2+ AZs + user data that attaches the Elastic IP (with an instance role).
- "Automatically recover an instance after a hardware failure, same IP" → EC2 automatic recovery (CloudWatch
StatusCheckFailed_System). - "Run custom actions when an ASG launches or terminates an instance" → lifecycle hooks.
Common traps
- "Attach the same EBS volume in the other AZ." EBS volumes are AZ-bound; use a snapshot (or keep the data on EFS).
- "An ASG of one gives zero downtime." A replacement takes minutes to launch; it's high availability, not fault tolerance.
AWS documentation
High performance computing (HPC)
The AWS services that help run HPC workloads - data transfer, EC2 instances and cluster placement groups, enhanced networking with ENA and the Elastic Fabric Adapter, high-IOPS storage like FSx for Lustre, and automation with AWS Batch, ParallelCluster and AWS PCS.
Well-Architected Framework and Trusted Advisor
The AWS Well-Architected Framework's general design principles and six pillars, the free Well-Architected Tool for reviewing workloads, AWS Trusted Advisor's checks and support plans, and where to find reference architectures.