我正在尝试使用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对象没有属性listrongtack_resources "这个堆栈运行9个资源,我想获得一个资源ARN信息。希望你能帮助我。
您混淆了客户端级和资源级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()))