英文:
Using AWS CLI, how to query all instances whose ID does not match a list of IDs?
问题
I would like to know if it's possible using AWS Cli tools to query all the instances that do not match a list of IDs.
我们想知道是否可以使用AWS Cli工具来查询不匹配ID列表的所有实例。
We are using a tool to create/update/delete instances and this tool has its own database to list existing instances. But before this tool, all were made by hand.
我们正在使用一个工具来创建/更新/删除实例,这个工具有自己的数据库列出现有的实例。但在使用这个工具之前,所有操作都是手工完成的。
Actually, with have a lot of dummy instances that are not currently used and that we want to delete.
实际上,我们有很多虚拟实例目前没有使用,我们希望删除它们。
We have the list of used instances and we want to delete all the others. As we have like 500 instances used and 2500 not used, it's a bit painful to do it by hand.
我们有已使用实例的列表,我们希望删除所有其他实例。由于已使用实例有大约500个,未使用实例有2500个,手工操作有点繁琐。
So I would like to query IDs of instances that do not match instances currently in use.
因此,我想查询不匹配当前正在使用的实例的ID。
Thanks
谢谢
英文:
I would like to know if it's possible using AWS Cli tools to query all the instances that do not match a list of IDs.
We are using a tool to create/update/delete instances and this tool has its own database to list existing instances. But before this tool, all were made by hand.
Actually, with have a lot of dummy instances that are not currently used and that we want to delete.
We have the list of used instances and we want to delete all the others. As we have like 500 instances used and 2500 not used, it's a bit painful to do it by hand.
So I would like to query IDs of instances that do not match instances currently in use.
Thanks
答案1
得分: 1
在bash中,你可以像这样做:
INSTANCE_IDS_BLACKLIST=("i-78b7e6f3e455238dc" "i-78b7e6f3e455238db")
FILTER=$(printf "InstanceId!=\`%s\`\n && " "${INSTANCE_IDS_BLACKLIST[@]}" | head -n -1 | tr -d "\n")
aws ec2 describe-instances --query "Reservations[].Instances[?${FILTER}]"
这将返回任何ID不匹配INSTANCE_IDS_BLACKLIST
数组中任何ID的实例。
<details>
<summary>英文:</summary>
In bash, you could do something like this:
```bash
INSTANCE_IDS_BLACKLIST=("i-78b7e6f3e455238dc" "i-78b7e6f3e455238db")
FILTER=$(printf InstanceId!=\`"%s\`\n && " "${INSTANCE_IDS_BLACKLIST[@]}" | head -n -1 | tr -d "\n")
aws ec2 describe-instances --query "Reservations[].Instances[?${FILTER}]"
This will return any instances whose id does not match any of those present in the INSTANCE_IDS_BLACKLIST
array.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论