AWS CLI-获取名称以字符串开头的所有CloudFormation堆栈

时间:2019-04-05 13:49:44

标签: amazon-web-services amazon-cloudformation aws-cli jmespath

我应该使用什么查询来获取以特定字符串开头的所有CloudFormation堆栈?

我尝试了以下查询,但是它总是返回一个空数组:

import  csv
import io
filePath="""name tribe id Score1 Score2 Score3 Score4
Aang Normad N321B 89 67 54 78
Gyatso Omaticay O111C 54 78 65 54
"""

avatar_id=  input ("Enter Avatar ID:")    
reader = csv.DictReader(io.StringIO(filePath),delimiter=' ')  
for row in reader:
    print(row)
    if avatar_id in row.get('id',''):
        user,tribe,id, *scores= row.values()
        average= sum([int(score) for score in scores])/4
        print("==============================") 
        break
    else:
        x=None
if x is None:
    print('No avatar found')
else:
    print("{} score is {}".format(avatar_id,x))

我们帐户中的所有筹码都以“ HD-”开头,因此其返回值应与

相同
aws cloudformation describe-stacks --no-paginate --query "Stacks[?StackName!='null']|[?starts_with(StackName,'HD-') == 'true']"

但它返回

aws cloudformation describe-stacks --no-paginate

1 个答案:

答案 0 :(得分:1)

此命令正常工作:

aws cloudformation describe-stacks --no-paginate --query \
  'Stacks[?StackName!=`null`]|[?contains(StackName, `Release`) == `true`].StackName'

您似乎需要在查询中使用`而不是'。