微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CloudFormation 堆栈资源

如何解决CloudFormation 堆栈资源

我正在尝试使用 boto3 接收堆栈资源 ARN 信息。 我尝试使用:

import boto3

client = boto3.resource('cloudformation',aws_access_key_id='xxxxxxxx',aws_secret_access_key='xxxxxxxxxxxx')

response = client.list_stack_resources(
  StackName='ORG-ROLES')

我收到“AttributeError: 'cloudformation.ServiceResource' 对象没有属性 'list_stack_resources'” 这个Stack运行了9个资源,我想获取一个资源ARN信息。 希望你能帮助我。

解决方法

您混淆了 client-levelresource-level API。您需要使用其中之一。这是每个示例。

import boto3

session = boto3.Session(profile_name='xxxx',region_name='us-east-1')

STACK_NAME = 'ORG-ROLES'

# Use client-level API
client = session.client('cloudformation')
response = client.list_stack_resources(StackName=STACK_NAME)
print('Client API:',response['StackResourceSummaries'])

# Use resource-level API
resource = session.resource('cloudformation')
stack = resource.Stack(STACK_NAME)
print('Resource API:',list(stack.resource_summaries.all()))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。