amazon-web-servicesamazon-ec2aws-cliaws-opsworks

Delete OpsWorks EC2 instance using AWS CLI


I'm trying to delete an instance using this command:

aws opsworks delete-instance --instance-id i-04bcd091c06c14e86

But I'm getting an error:

An error occurred (ValidationException) when calling the DeleteInstance operation: Please provide a valid OpsWorks instance ID, not an EC2 instance ID

I got the instance using

aws ec2 describe-instances | grep InstanceId

How do I get an opsworks instance?


Solution

  • If you need the OpsWorks instance ID then you need to use the OpsWorks version of the describe-instances command:

    aws opsworks describe-instances
    

    Edit: If you just want to delete an EC2 instance that is not a part of a stack, use:

    aws ec2 terminate-instances --instance-ids <instance-id>