从名称获取AWS EMR集群ID [英] Get AWS EMR Cluster ID from Name
问题描述
AWS CLI命令 aws emr list-clusters
返回以下json.是否可以通过bash或groovy来使用Name来获取ID?我不能只使用Id,因为我要删除群集并仅使用相同的名称来重建它们.因此,我知道集群的名称是"my-cluster",我想以某种方式使用它来获取集群的ID.最终的情况是我实际上想要群集的Master公共DNS.
AWS CLI command aws emr list-clusters
returns the following json. Is there a way through bash or groovy that I can use the Name to get the Id? I can't just use the Id becauseI am deleting clusters and rebuilding them with only the same name. So I know the name of the cluster is "my-cluster" and I would like to use it somehow to get the Id of the cluster. End case is I actually want the Master public DNS of the cluster.
{
"Clusters": [
{
"Status": {
"Timeline": {
"ReadyDateTime": 1433200405.353,
"CreationDateTime": 1433199926.596
},
"State": "WAITING",
"StateChangeReason": {
"Message": "Waiting after step completed"
}
},
"NormalizedInstanceHours": 6,
"Id": "j-3SD91U2E1L2QX",
"Name": "my-cluster"
},
{
"Status": {
"Timeline": {
"ReadyDateTime": 1433200405.353,
"CreationDateTime": 1433199926.596
},
"State": "WAITING",
"StateChangeReason": {
"Message": "Waiting after step completed"
}
},
"NormalizedInstanceHours": 6,
"Id": "j-3S281UEK8L2LW",
"Name": "my-cluster2"
}
]
}
推荐答案
您可以使用 query
参数来实现您要尝试的功能.该命令将如下所示:
You can use the query
parameter to achieve what you are trying. The command will look like below:
aws emr list-clusters --query 'Clusters[?Name==`my-cluster`].Id' --output text
You can find the complete documentation for the query
parameter here.
这篇关于从名称获取AWS EMR集群ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!