Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cfn_response to be called inside handler #4

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Allow cfn_response to be called inside handler #4

wants to merge 7 commits into from

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.

None yet

1 participant