/miltons-red-stapler

A demo resource for the AWS CloudFormation CLI written in Python with at least 3 more pieces of flair than Brian

Primary LanguagePython

Miltons::Red::Stapler

Congratulations on starting development! Next steps:

  1. Write the JSON schema describing your resource, miltons-red-stapler.json
  2. Implement your resource handlers in miltons_red_stapler/handlers.py

Don't modify models.py by hand, any modifications will be overwritten when the generate or package commands are run.

Implement CloudFormation resource here. Each function must always return a ProgressEvent.

ProgressEvent(
    # Required
    # Must be one of OperationStatus.IN_PROGRESS, OperationStatus.FAILED, OperationStatus.SUCCESS
    status=OperationStatus.IN_PROGRESS,
    # Required on SUCCESS (except for LIST where resourceModels is required)
    # The current resource model after the operation; instance of ResourceModel class
    resourceModel=model,
    resourceModels=None,
    # Required on FAILED
    # Customer-facing message, displayed in e.g. CloudFormation stack events
    message="",
    # Required on FAILED: a HandlerErrorCode
    errorCode=HandlerErrorCode.InternalFailure,
    # Optional
    # Use to store any state between re-invocation via IN_PROGRESS
    callbackContext={},
    # Required on IN_PROGRESS
    # The number of seconds to delay before re-invocation
    callbackDelaySeconds=0,
)

Failures can be passed back to CloudFormation by either raising an exception from cloudformation_cli_python_lib.exceptions, or setting the ProgressEvent's status to OperationStatus.FAILED and errorCode to one of cloudformation_cli_python_lib.HandlerErrorCode. There is a static helper function, ProgressEvent.failed, for this common case.

What's with the type hints?

We hope they'll be useful for getting started quicker with an IDE that support type hints. Type hints are optional - if your code doesn't use them, it will still work.