def update(args):
"""update or create a stack in AWS."""
stack = args.stack
if stack not in local_stacks():
LOG.error('no such stack: ' + stack)
return
if stack not in remote_stacks().keys() and not args.create_missing:
LOG.warning(
'stack ' + stack + ' does not exist in AWS, add --create_missing to create a new stack')
return
# read template and parameters
tpl_body = load_template(stack, True)
params = load_parameters(stack)
# action
cfn = get_cfn()
last_event = None
try:
if stack in remote_stacks().keys():
LOG.info('updating stack %s', stack)
last_event = fetch_all_stack_events(stack)[-1]['Timestamp']
stack_id = cfn.update_stack(
StackName=stack,
TemplateBody=tpl_body,
Parameters=params,
Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']
)['StackId']
LOG.info('created stack with physical id %s', stack_id)
else:
LOG.info('creating stack %s', stack)
stack_id = cfn.create_stack(
StackName=stack,
TemplateBody=tpl_body,
Parameters=params,
Capabilities=['CAPABILITY_IAM', 'CAPABILITY_NAMED_IAM']
)['StackId']
LOG.info('created stack with physical id %s', stack_id)
except botocore.exceptions.ClientError as err:
LOG.warning(str(err))
return
except botocore.exceptions.ParamValidationError as err:
LOG.warning(str(err))
return
# synchronous mode
if args.wait or args.events:
wait(stack, show_events=args.events, last_event=last_event)
评论列表
文章目录