def handler()

in lib/custom_resources/create_and_attach_scp.py [0:0]


def handler(event, context):
    LOGGER.info("Received event: " + json.dumps(event, indent=2))

    job_id = get_job_id(event)

    # Initialize status
    status = "FAILED"

    try:
        action_name = get_action_name(job_id)
        LOGGER.info("Action name - {}".format(action_name))

        if action_name == 'createSCPs':
            create_policies(event)
        elif action_name == 'attachSCPs':
            attach_policies(event)

        status = "SUCCESS"

        """Setting the job status success"""
        pipeline_client.put_job_success_result(
            jobId=job_id
        )
    except BaseException as ex:
        LOGGER.exception(ex)

        """Setting the job status failure"""
        pipeline_client.put_job_failure_result(
            jobId=job_id,
            failureDetails={
                'type': 'JobFailed',
                'message': str(ex)
            }
        )
    finally:
        response_body = {
            'Status': status,
            'Event': event,
            'Reason': 'See the details in CloudWatch Log Stream: ' + context.log_stream_name
        }
        LOGGER.info(json.dumps(response_body, indent=2))