Lab 009: Enable Termination Protection for EC2 Instance
Requirements
As part of the migration, there were some components created under the AWS account. The Nautilus DevOps team created one EC2 instance where they forgot to enable the termination protection which is needed for this instance.An instance named devops-ec2 already exists in us-east-1 region. Enable termination protection for the same.
Note
The Requirements section is preserved as-is. The steps below use one CLI path to enable termination protection.
Prerequisites
- AWS CLI is installed and authenticated.
- The target instance exists in
us-east-1. - Your identity can describe and modify EC2 instance attributes.
Steps
VM_NAME=devops-ec2
INSTANCE_ID=$(aws ec2 describe-instances \
--region us-east-1 \
--filters "Name=tag:Name,Values=$VM_NAME" \
--query "Reservations[0].Instances[0].InstanceId" \
--output text)
echo "$INSTANCE_ID"
aws ec2 modify-instance-attribute \
--region us-east-1 \
--instance-id "$INSTANCE_ID" \
--disable-api-termination "{\"Value\":true}"
Verification
- Confirm termination protection is enabled for
devops-ec2.
aws ec2 describe-instance-attribute \
--region us-east-1 \
--instance-id "$INSTANCE_ID" \
--attribute disableApiTermination \
--output json