【发布时间】:2016-11-10 04:18:00
【问题描述】:
我正在使用 AWS Lambda(带有嵌套堆栈)使用 create_stack api。但我想将每个堆栈 ID 存储在作为嵌套堆栈的一部分创建的 S3 中。 我将 python 用于 Lambda 函数。
每当一个单独的堆栈被创建为嵌套堆栈(cloudformation)的一部分时,它都会为每个堆栈附加唯一的 ID,如下所示
MYnestedStack-Ec2Stack-1WQDHSJFIFNFN
我想将此值存储在 S3 存储桶中,以便我可以使用该 ID 来删除堆栈,而无需手动转到 AWS cloudformation 控制台来删除它。..
我已经按照下面@ataylor 的建议进行了尝试,但出现错误
“响应 JSON 序列化时出错:datetime.datetime(2016, 7, 12, 15, 23, 16, 451000, tzinfo=tzlocal()) is not JSON serializable"
import boto3
import time
import json
client = boto3.client('cloudformation')
response = client.describe_stack_resources(
StackName='Mystack',
LogicalResourceId='Ec2Stack'
)
def lambda_handler(event, context):
return response
我也尝试了下面的代码并得到错误
“响应的 JSON 序列化过程中出错:cloudformation.StackResource(stack_name='Mystack',logical_id='Ec2Stack') is not JSON serializable”
import boto3
import time
import json
cloudformation = boto3.resource('cloudformation')
stack_resource = cloudformation.StackResource('prodUpgradeForchestartorFullStack','ApplicationStack')
def lambda_handler(event, context):
return stack_resource
请推荐!!
【问题讨论】:
标签: python amazon-web-services amazon-s3 aws-lambda amazon-cloudformation