Chapter 9. Working with CDK Custom Resources
Sometimes there are no published L2 or L3 CDK constructs that meet your needs. One alternative to working with L1 constructs is to use something called a CDK custom resource. CDK custom resources are essentially AWS Lambda functions that deploy temporarily, launch some resources using an SDK, and then clean up, saving their state so that you can make modifications. This allows you to use the CDK to deploy resources that are not yet supported with L2 or L3 constructs but are supported by the AWS SDKs.
For our project, we will deploy an Amazon Q Business application using a CDK custom resource. Amazon Q Business lets you point foundational large language models at your private data, keeping it private while gaining the power of a fully managed generative AI (GenAI) chatbot for your own business use. In our case, we will use Amazon Q to summarize, identify patterns in, and make recommendations about our electric utility consumption data. Using custom resources really allows you to build quickly and bring the support of the SDKs to the CDK. At the time of writing this book, Amazon Q was not yet supported as an L2 or L3 construct in the CDK. At the time of reading this book, it may be supported, but you can still deploy the custom resource to learn how to do it. Think of a custom resource as a way to extend the CDK to support any AWS service that has an SDK until it is available as an L2 or L3 constructs either because someone else contributed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access