如何查找具有公共名称前缀的所有启动配置名称

how to find all launch configuration name which has a common name prefix

我想查找在启动配置名称中包含文本的所有启动配置名称。

例如:假设有 3 个启动配置名称 'awsLC1' 'xyzLC2' 'aLC3' 'pqrst'

我想要一个查询,它使用 aws CLI 为我获取 3 个启动配置。

我尝试使用 JMESpath 编写以下查询,但没有成功,因为 LaunchConfigurtionName 不是数组。

 aws autoscaling describe-launch-configurations --query LaunchConfigurations[? LaunchConfigurationName [? contains(@,'LC')]].LaunchConfigurationName" --output text

谢谢!

您可以简单地更改 contains() 来评估您要检查的字段,而不是使用 @ 数组语法。来自 contains() 文档:

boolean contains(array|string $subject, any $search)

If the provided $subject is a string, this function returns true if the string contains the provided $search argument.

查找包含 'LC' 的启动配置名称的示例:

contains(LaunchConfigurationName,'LC')

完整示例:

aws autoscaling describe-launch-configurations --query "LaunchConfigurations[?contains(LaunchConfigurationName,'LC')].LaunchConfigurationName" --output text

进一步阅读: