使用boto3进行Cloudformation通配符搜索

2024-05-07 17:35:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我的任务是使用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进行类似的包含搜索。有可能吗?在

谢谢!在


Tags: 项目字符串脚本名称bashjson类型堆栈
1条回答
网友
1楼 · 发布于 2024-05-07 17:35:00

是的,有可能。您需要的是:

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”。在

相关问题 更多 >