我正在尝试使用下面的boto3获取CloudFormation堆栈的详细信息
import boto3
import json
def lambda_handler(event, context):
global cnfOutput
cnfOutput = cfn1.describe_stacks(StackName='cfn-init-stack1')
cnf2 = json.dumps(cnfOutput)
return cnf2
下面是我打印cfnOutput时得到的输出。我试着去做json.dumps文件得到错误。需要帮助吗
^{pr2}$低于错误
File "/usr/lib64/python2.7/json/encoder.py", line 184, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: datetime.datetime(2018, 10, 17, 12, 40, 10, 783000, tzinfo=tzlocal()) is not JSON serializable
如何将原始字典转换为JSON
以下内容对我来说毫无问题:
但是,当我运行它时:
^{pr2}$我和你犯了同样的错误。在
如果您可以在调用
json.dumps
之前将datetime.datetime(2018, 10, 17, 12, 40, 10, 783000, tzinfo=tzlocal())
的结果转换为字符串,那么它应该可以解决您的问题。在如何从原始字典中提取OutputValue
在问题中使用字典时,我的输出是
ec2-51-111-211-211.us-west-2.compute.amazonaws.com
(在将datetime.datetime()
结果转换为字符串之后,但在将整个字典转换为JSON之前)。在相关问题 更多 >
编程相关推荐