As discussed in the introduction to CloudFormation in Chapter 1, AWS Fundamentals, it's common for there to be cases where you need more advanced behavior than what is available by default in CloudFormation. Before custom resources, this led AWS developers down the path of doing most of their automation in CloudFormation, and then running some command-line interface (CLIs) commands to fill in the gaps.
Fast forward to today, and the emerging pattern is to use a custom resource to delegate to an AWS Lambda function. Lambda can fill in the gaps by making API calls on your behalf. While it's also possible to create a custom resource that communicates with your custom code via a Simple Notification Service (SNS), and a compute resource such as an Elastic Compute Cloud (EC2) instance, Lambda should be your first...