AWS ec2 describe-instance-status only for instance

2019-09-05 15:33发布

问题:

Is there a easy way to run aws ec2 describe-instance-status and only display the information of instances if they have any Scheduled Events?

回答1:

You can use the --query arg for this:

$ aws ec2 describe-instance-status --query 'InstanceStatuses[?length(Events || `[]`) > `0`]'


回答2:

Or you can use --filter CLI argument for this:

$ aws ec2 describe-instance-status --filters "Name=event.code,Values='instance-reboot','system-reboot','system-maintenance','instance-retirement','instance-stop'"

This filters statuses only down to the ones with events with the specified code. Since this command lists out all possible codes, you basically get only the statuses with one or more events.