Skip to main content

Lab 008: Enable Stop Protection for EC2 Instance



Requirements

As part of the migration, there were some components added to the AWS account. Team created one of the EC2 instances where they need to make some changes now.There is an EC2 instance named devops-ec2 under us-east-1 region, enable the stop protection for this instance.


Note

This page preserves the original requirement text and uses one direct CLI workflow to enable stop protection.

Prerequisites

  • AWS CLI is installed and authenticated.
  • The instance devops-ec2 exists in us-east-1.
  • Your identity can run ec2:ModifyInstanceAttribute and ec2:DescribeInstances.

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-stop "{\"Value\":true}"

Verification

  • Confirm stop protection is enabled for devops-ec2.
aws ec2 describe-instances \
--region us-east-1 \
--instance-ids "$INSTANCE_ID" \
--query "Reservations[0].Instances[0].{InstanceId:InstanceId,Name:Tags[?Key=='Name']|[0].Value,DisableApiStop:DisableApiStop}" \
--output table

Resources