我正在尝试部署 https://s3.amazonaws.com/serverless-chatbot-code/chatbot.yaml 使用boto3库函数create_stack但收到错误
“CreateStack不能与包含Transforms的模板一起使用”
如何使用boto3部署此堆栈?
感谢。
答案 0 :(得分:4)
评论是正确的,您必须先创建更改集,然后在更改集创建完成后执行更改集。代码大纲如下:
client = boto3.client('cloudformation')
# Helper function to retrieve change set status
def changeSetStatus(change_set_name, client):
response = client.describe_change_set(
ChangeSetName=change_set_name,
)
return response['Status']
# Create change set
cs_response = client.create_change_set(
StackName=stackname,
TemplateURL=templateurl,
Parameters=params,
Capabilities=[capabilities],
ChangeSetType="CREATE",
ChangeSetName=stackname + "-cs"
)
#Remove print statements, here for illustration
print(str(cs_response))
change_set_name = cs_response['Id']
# Wait until change set status is CREATE_COMPLETE
while True:
response = change_set_status(change_set_name, client)
print(str(response))
time.sleep(10)
if response == 'CREATE_COMPLETE':
break
# Execute change set
ex_response = client.execute_change_set(
ChangeSetName=change_set_name
)