mark18
mark18

Reputation: 23

AWS CLI Windows Command to Terminate All EC2 Instances

I need a single Windows CMD command that terminate all instances from Ohio region. I found this commands but its not working.

aws ec2 terminate-instances \
    --region us-east-2 \
    --instance-ids (aws ec2 describe-instances --query "Reservations[].Instances[].[InstanceId]" --region us-east-2)

Upvotes: 1

Views: 402

Answers (1)

Brandon Miller
Brandon Miller

Reputation: 5065

Try this out in powershell:

foreach ($id in (aws ec2 describe-instances --filters --query "Reservations[].Instances[].[Instance
Id]" --output text --region us-east-2)) { aws ec2 terminate-instances --instance-ids $id }

You can pass the --dry-run flag with terminate instances to confirm first if you'd like.

Upvotes: 1

Related Questions