我试图从我的OpsWorks堆栈中使用python和boto3获取自定义json。获取名称是好的,但如果我想获得CustomJson - KeyError。不知道为什么。Python Boto3 OpsWorks KeyError通过获取CustomJson
import boto3
import traceback
client = boto3.client('opsworks')
response = client.describe_stacks()
max_elements = len(response['Stacks'])
for i in range(max_elements):
stack_Name = response['Stacks'][i]['Name'] # works
try:
stack_CustomJson = response['Stacks'][i]['CustomJson'] # KeyError
except:
traceback.print_exc()
这是控制台输出:
$ python3 get_custom_json.py
Traceback (most recent call last):
File "get_custom_json.py", line 27, in get_opsworks_details
stack_CustomJson = response['Stacks'][i]['CustomJson']
KeyError: 'CustomJson'
阅读从http://boto3.readthedocs.org/en/latest/reference/services/opsworks.html#OpsWorks.Client.describe_stacks的文档我没有看到“名称”和除了CustomJson“CustomJson”之间的区别是一个JSON对象。我必须改变它吗?
Thx提前