Skip to content

Conversation

@benkehoe
Copy link

@benkehoe benkehoe commented Nov 3, 2015

If the handler knows the physical resource ID, it has to call cfn_response itself. I've made Status more complex to allow the following workflow (while allowing backwards compatibility):

@handler_decorator()
def handler(event, context):
    valid = validate(event)
    if not valid:
        return Status.getFailed('event failed validation')
    try:
        success, physical_resource_id, data = handler_logic(event)
    except Exception, e:
        return Status.getFailed(str(e))

    status = Status.SUCCESS if success else Status.getFailed('failed')
    resp = cfn_response(event, context, status, 
            physical_resource_id=physical_resource_id, response_data=data)
    # optionally do something with response object

    return Status.getFinished(status) # wrapper still takes care of cleanup based on status

The new status can also be used without calling cfn_response in the handler:

@handler_decorator()
def handler(event, context):
    valid = validate(event)
    if not valid:
        return Status.getFailed('event failed validation')
    try:
        success, physical_resource_id, data = handler_logic(event)
    except Exception, e:
        return Status.getFailed(str(e))

    status = Status.SUCCESS if success else Status.getFailed('failed')
    return status, data # wrapper calls cfn_response

I also made handler_decorator work when it's used without parentheses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant