简体   繁体   English

CloudFormation 堆栈资源

[英]CloudFormation Stack resources

I am trying to receive Stack resources ARN information using boto3.我正在尝试使用 boto3 接收堆栈资源 ARN 信息。 I tried to use:我尝试使用:

import boto3

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

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

I get "AttributeError: 'cloudformation.ServiceResource' object has no attribute 'list_stack_resources'" This Stack runs 9 resources, I want to get one resource ARN information.我得到“AttributeError: 'cloudformation.ServiceResource' object has no attribute 'list_stack_resources'” 这个堆栈运行 9 个资源,我想获取一个资源 ARN 信息。 Hope you can help me.希望您能够帮助我。

You're mixing up the client-level and resource-level APIs.您正在混淆客户端级资源级API。 You need to use one or the other.您需要使用其中一种。 Here's an example of each.这是每个示例。

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()))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM