【问题标题】:Cloudformation wildcard search with boto3使用 boto3 进行 Cloudformation 通配符搜索
【发布时间】:2019-03-08 18:34:24
【问题描述】:
我的任务是使用 boto3 库将我的团队使用的一些执行各种 cloudformation 任务的 bash 脚本转换为 Python。我目前被困在一个项目上。我似乎无法确定如何在云形成堆栈名称包含字符串的情况下进行通配符类型搜索。
我使用 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 进行类似的包含搜索。有可能吗?
谢谢!
【问题讨论】:
标签:
python
amazon-web-services
amazon-cloudformation
boto3
【解决方案1】:
是的,这是可能的。您正在寻找的是以下内容:
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”。