Wiki
Clone wikicfn-custom-resource / Home
Before you start
Make sure you are familiar with the Custom Resource documentation section. In particular, make yourself familiar with the Request objects and types.
Basic Usage
Decoratos
The library provides 3 decorators to handle each request type: create()
, update()
, delete()
.
When your lambda is executed by CloudFormation, the appropriate function will be invoked.
For example, if requests type is Create
, the function that is decorated with the create()
decorated will be invoked.
Lambda's function name
Import lambda_handler
and use it as the entry point. For example, if your lambda's file name is my_lambda.py
and it's content is:
from cfn_custom_resource import lambda_handler ...
function name should be my_lambda.lambda_handler
.
Request properties
Decorated functions should have two parameters: event
and context
. These allows your function to access the lambda event
dict and the context
object.
This allows your decorated functions to access additional properties provided from your CF stack:
@create() def create(event, context): # Name is a property from CF stack name = event['ResourceProperties']['Name']
Function's return values
Both create()
& update()
decorated functions must return a tuple in the form of str, dict
.
The first item is the PhysicalResourceId
of the provisioned resource. The second item is the Data
dict. This dict allows returning attributes back to the CloudFormation stack and accessible by Fn::GetAtt
.
delete()
decorated function should return None
.
Updated