Lab: Cleanup EC2 Instance

Open new codespace terminal.

alt text

Attackers EC2 Deletion Steps:

  • Change the directory
cd /workspaces/ecr_eks_security_masterclass_public/eks/jenkins_cve
  • Terminate the EC2 instance.

If changed to other region, then replace that region.

export AWS_DEFAULT_REGION=us-east-1

export INSTANCE_ID=$(aws ec2 describe-instances --filters "Name=key-name,Values=peachycloudsecurity" "Name=instance-state-name,Values=running" --query 'Reservations[0].Instances[0].InstanceId' --output text --region $AWS_DEFAULT_REGION)

aws ec2 terminate-instances --instance-ids $INSTANCE_ID --region $AWS_DEFAULT_REGION
  • Check instance termination.
aws ec2 describe-instances --instance-ids $INSTANCE_ID --region $AWS_DEFAULT_REGION --query 'Reservations[0].Instances[0].State.Name'
  • Delete the key pair.
aws ec2 delete-key-pair --key-name peachycloudsecurity --region $AWS_DEFAULT_REGION
  • Remove the local key file:
rm -f peachycloudsecurity.pem