我的任务是使用boto3库将我的团队执行的一些bash脚本转换为Python,这些脚本执行各种cloudformation任务。我目前只停留在一个项目上。我似乎无法确定在云形成堆栈名称包含字符串的情况下如何进行通配符类型搜索。
我使用AWS CLI的bash版本如下:
aws cloudformation --region us-east-1 describe-stacks --query "Stacks[?contains(StackName,'myString')].StackName" --output json > stacks.out
这在cli上有效,将结果输出到json文件,但是我无法在线找到任何示例来对boto3和Python进行包含的相似搜索。有可能吗?
谢谢!
答案 0 :(得分:0)
是的,有可能。您正在寻找以下内容:
import boto3
# create a boto3 client first
cloudformation = boto3.client('cloudformation', region_name='us-east-1')
# use client to make a particular API call
response = cloudformation.describe_stacks(StackName='myString')
print(response)
# as an aside, you'd need a different client to communicate
# with a different service
# ec2 = boto3.client('ec2', region_name='us-east-1')
# regions = ec2.describe_regions()
其中response
是一个Python字典,除其他外,它将包含堆栈“ myString”的描述。