def check_change_set_status(cf, job_id, stack, change_set): status = get_change_set_status(cf, stack, change_set) if status == 'CREATE_COMPLETE': put_job_success(job_id, 'Change set created') elif status == 'CREATE_IN_PROGRESS': continue_job_later(job_id, 'Change set still in progress') else: put_job_failure(job_id, 'Change set failed')
def check_change_set_status(cf, job_id, stack, change_set): status = get_change_set_status(cf, stack, change_set) if status == 'CREATE_COMPLETE': put_job_success(job_id, 'Change set created') elif status == 'CREATE_IN_PROGRESS': continue_job_later(job_id, 'Change set still in progress') else: put_job_failure(job_id, 'Change set failed')
def execute_change_set_handler(job_id, job_data, params: PipelineUserParameters): s3, cf = setup_s3_client(job_data), boto3.client('cloudformation') if 'continuationToken' in job_data: if check_stack_status(cf, job_id, params.StackName): generate_output_artifact(s3, job_data, params, get_stack_output(cf, params.StackName)) else: if not change_set_exists(cf, params.StackName, params.ChangeSetName): raise Exception("Change set {} cannot be executed because doesn't exist".format(params.ChangeSetName)) execute_change_set(cf, params.StackName, params.ChangeSetName) continue_job_later(job_id, 'Stack create started')
def delete_stack_handler(job_id, job_data, params: PipelineUserParameters): cf = boto3.client('cloudformation') if not stack_exists(cf, params.StackName): put_job_success(job_id, "Stack do not exist") return if 'continuationToken' in job_data: check_stack_status(cf, job_id, params.StackName) else: stack_delete(cf, params.StackName, params.RoleArn) continue_job_later(job_id, 'Stack create started')
def delete_stack_handler(job_id, job_data, params: PipelineUserParameters): cf = boto3.client('cloudformation') if not stack_exists(cf, params.StackName): put_job_success(job_id, "Stack do not exist") return if 'continuationToken' in job_data: check_stack_status(cf, job_id, params.StackName) else: stack_delete(cf, params.StackName, params.RoleArn) continue_job_later(job_id, 'Stack create started')
def create_replace_change_set_handler(job_id, job_data, params: PipelineUserParameters, in_artifacts): s3, cf = setup_s3_client(job_data), boto3.client('cloudformation') if 'continuationToken' in job_data: check_change_set_status(cf, job_id, params.StackName, params.ChangeSetName) else: if change_set_exists(cf, params.StackName, params.ChangeSetName): delete_change_set(cf, params.StackName, params.ChangeSetName) template_url, config, update = generate_template_and_config(s3, cf, job_id, params, in_artifacts) create_change_set(cf, params.StackName, params.ChangeSetName, template_url, config, params.RoleArn) continue_job_later(job_id, 'Stack create started')
def check_stack_status(cf, job_id, stack): status = get_stack_status(cf, stack) if status in ['UPDATE_COMPLETE', 'CREATE_COMPLETE']: put_job_success(job_id, 'Stack completed') return True elif status in ['UPDATE_IN_PROGRESS', 'UPDATE_ROLLBACK_IN_PROGRESS', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS', 'CREATE_IN_PROGRESS', 'ROLLBACK_IN_PROGRESS', 'DELETE_IN_PROGRESS', 'UPDATE_COMPLETE_CLEANUP_IN_PROGRESS']: continue_job_later(job_id, 'Stack still in progress: {}'.format(status)) elif status in ['REVIEW_IN_PROGRESS']: put_job_failure(job_id, 'Stack in REVIEW_IN_PROGRESS state') else: put_job_failure(job_id, 'Stack failed: {}'.format(status)) return False
def start_stack_create_or_update(cf, job_id, stack_name, template_url, config: PipelineStackConfig, update=False, role_arn=None): if update: status = get_stack_status(cf, stack_name) if status not in ['CREATE_COMPLETE', 'ROLLBACK_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE']: put_job_failure(job_id, 'Stack cannot be updated when status is: ' + status) return if update_stack(cf, stack_name, template_url, config, role_arn): continue_job_later(job_id, 'Stack update started') else: continue_job_later(job_id, 'There were no stack updates') else: create_stack(cf, stack_name, template_url, config, role_arn) continue_job_later(job_id, 'Stack create started')