from __future__ import print_function from crhelper import CfnResource import logging import boto3 logger = logging.getLogger(__name__) # Initialise the helper, all inputs are optional, this example shows the defaults helper = CfnResource(json_logging=False, log_level='DEBUG', boto_level='CRITICAL') try: ## Init code goes here # secrets_client = boto3.client('secretsmanager') pass except Exception as e: helper.init_failure(e) @helper.create def create(event, context): logger.info("Got Create") # Optionally return an ID that will be used for the resource PhysicalResourceId, if None is returned an ID will be # generated. If a poll_create function is defined return value is ignored return "MyResourceId" @helper.update def update(event, context): logger.info("Got Update") # If the update resulted in a new resource being created, return an id for the new resource. CloudFormation will send # a delete event with the old id when stack update completes @helper.delete def delete(event, context): logger.info("Got Delete") # Delete never returns anything. Should not fail if the underlying resources are already deleted. Desired state. @helper.poll_create def poll_create(event, context): logger.info("Got create poll") # Return a resource id or True to indicate that creation is complete. if True is returned an id will be generated return True def handler(event, context): helper(event, context)