使用AWS CLI,如何查询所有实例的ID与ID列表不匹配的情况?

huangapple go评论52阅读模式
英文:

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=(&quot;i-78b7e6f3e455238dc&quot; &quot;i-78b7e6f3e455238db&quot;)
FILTER=$(printf InstanceId!=\`&quot;%s\`\n &amp;&amp; &quot; &quot;${INSTANCE_IDS_BLACKLIST[@]}&quot; | head -n -1 | tr -d &quot;\n&quot;)
aws ec2 describe-instances --query &quot;Reservations[].Instances[?${FILTER}]&quot;

This will return any instances whose id does not match any of those present in the INSTANCE_IDS_BLACKLIST array.

huangapple
  • 本文由 发表于 2023年5月24日 21:29:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定