- Get the source code
git clone https://github.com/CloudSnorkel/cfm-reslib.git``
- Switch to the code directory
- Install requirements
pip install -r requirements.txt
- Create a virtual environment with all of the requirements
Unit tests can be executed using py.test or simply with:
poetry run py.test tests
The building process creates a CloudFormation template that can be deployed and expose
cfm-reslib to be imported by
other CloudFormation stacks. This template uses Lambda and its source code needs to be uploaded to a bucket. The build
script will create both a ZIP file and a template and will upload it to a given S3 bucket.
BUCKET=my-bucket-name poetry run python build.py $BUCKET
And just like when deploying the released versions of cfm-reslib, you can deploy this with
aws CLI tool.
BUCKET=my-bucket-name aws cloudformation create-stack --stack-name cfm-reslib --template-url https://s3.amazonaws.com/$BUCKET/cfm-reslib-latest.template --capabilities CAPABILITY_IAM
Or when updating:
BUCKET=my-bucket-name aws cloudformation update-stack --stack-name cfm-reslib --template-url https://s3.amazonaws.com/$BUCKET/cfm-reslib-latest.template --capabilities CAPABILITY_IAM
Note that you won't be able to deploy multiple stacks of cfm-reslib in the same region because the exported name has to be unique across all stacks in a certain region.
Adding Custom Resources
There are two methods to implement a new custom resource. You will need to create a class for your resource in both.
- If the custom resource uses just one boto3 call to create, update and delete a resource, you can inherit from
:class:`cfmreslib.boto.BotoResourceHandler`. Simply override all of the constants with the names of the methods that
need to be called and you're done. Check out
ElasticTranscoderPipelinefor an example.
- If you need more control of the process, inherit from :class:`cfmreslib.base.CustomResourceHandler`. You will have to
implement some methods that will be called for requests coming from CloudFormation. Check out
Route53Certificatefor an example.
Once you've added your custom resource, make sure to add it to
ALL_RESOURCES at the end of
.. autoclass:: cfmreslib.base.CustomResourceHandler :members: :member-order: bysource
.. autoclass:: cfmreslib.boto.BotoResourceHandler :members: NAME, SERVICE, CREATE_METHOD, UPDATE_METHODS, EXISTS_METHOD, EXIST_READY_QUERY, DELETE_METHOD, NOT_FOUND_EXCEPTION, EXTRA_PERMISSIONS :member-order: bysource