Handling updates, deletions, and failures of CRs
Our CR can create a database for us. But try to guess what will happen if you attempt to delete this resource or stack from CloudFormation.
It will fail to delete. Why? Because our CR function runs only one function, create_db
, it doesn’t matter which request type is received by CloudFormation. Exactly the same will happen if we try to update our database.
We need to add support for updates and deletes for our Lambda instance. We will start with the delete functionality because what we will do is make our CR immutable.
This means that whenever we change our custom database, the old one will always be deleted. Sounds scary? Unfortunately, this is the default behavior for CRs. Moreover, some AWS resources are also replaced (for example, a new resource is created while the old one is being deleted), even if nothing major is being changed.
Deleting resources
We will cover the delete operation in the following steps...