Skip to content

Advanced usage

Ben Kehoe edited this page Feb 8, 2018 · 1 revision

Validation

Classes may implement validate() and/or populate(). validate should return True if self.resource_properties is valid. populate can transfer the contents of self.resource_properties into object fields, if this is not done by validate.

Hooks

Some hooks are provided to override behavior. The first four are instance fields, since they may be set to functions that rely on instance fields. The last is a class field, since it is called by a class method.

  • finish_function, normally set to CloudFormationCustomResource.cfn_response, takes as input the custom resource object and deals with sending the response and cleaning up.
  • send_function, used within CloudFormationCustomResource.cfn_response, takes as input the custom resource object, a url, and the response_content dictionary. Normally this is set to CloudFormationCustomResource.send_response, which uses requests to send the content to its destination, using the vendored version in botocore.
  • generate_unique_id_prefix_function can be set to put a prefix on the id returned by generate_unique_id, for example if the physical resource id needs to be an ARN.
  • generate_physical_resource_id_function is used to get a physical resource id on a create call unless DISABLE_PHYSICAL_RESOURCE_ID_GENERATION is True. It takes the custom resource object as input.This is normally set to CloudFormationCustomResource.generate_unique_id, which generates a physical resource id like CloudFormation: {stack_id}-{logical resource id}-{random string} It also provides two keyword arguments:
    • prefix: if for example the physical resource id must be an arn
    • separator: defaulting to '-'.
  • BOTO3_SESSION_FACTORY takes no input and returns an object that acts like a boto3 session. If this class field is not None, it is used by get_boto3_session instead of creating a regular boto3 session. This could be made to use placebo for testing

Configuration

  • DELETE_LOGS_ON_STACK_DELETION: A boolean which, when True, will cause a successful stack deletion to trigger the deletion of the CloudWatch log group on stack deletion. If there is a problem during stack deletion, the logs are left in place. NOTE: this is not intended for use when the Lambda function is used by multiple stacks.

Clone this wiki locally