Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-resources): provider framework (#4572)
* feat(custom-resources): async custom resources `AsyncCustomResource` is a framework for defining robust custom resources. It makes it easy to implement providers for resources that require waiting for the resource to be ready, potentially for time period longer than the AWS Lambda timeout (15min at the moment). When a resource is created, the "begin" operation is invoked, and a state machine is triggered to wait for "complete" to indicate that it's done. It can also indicate that it's still waiting, in which case, Step Functions retry logic will kick in and "complete" will be called thereafter. If retries are exhausted, the resource operation will fail with a timeout. Any exceptions thrown from "begin" or "complete" will be reported as an operation failure to ensure that the custom resource does not hang the stack operation. * misc - change semantics to "onEvent" and "isComplete" - use Lambda layers to load user code - reorg project files * move aws-custom-resource to a subdirectory (both lib/ and test/) * good test coverage for async custom resource runtime handler * misc * support specifying execution role for each resource instance (very powerful) * always require that on-event will return a physical resource id (to avoid errors) * emit entire stack trace on errors * implement an integration test/sample (S3File) * add failing test * remove support for resource-specific roles * extract user handlers to separate lambdas, which means we are now language agnostic! * Misc * use RequestId as the name of the state machine execution due to limitations in the name * make handler names required to make sure users are aware that they have to implement them * implement another custom resource in the integration test which "waits" for the object to contain certain contents (tests async resources). * rename to ProviderFramework and add README * add types.d * a bunch of minor fixes * chore(custom-resources): reorg and migreate to jest As a preparation for adding the custom resource provider framework (#4572), which includes multiple files and tests, reorg the file structure of this module such that all files related to the `AwsCustomResource` construct will be under `lib/aws-custom-resource` and `test/aws-custom-resource`. Also, migrate all unit tests from nodeunit to jest. * Delete sdk-api-metadata.json * Update packages/@aws-cdk/custom-resources/lib/provider-framework/provider.ts Co-Authored-By: Jonathan Goldwasser <jogold@users.noreply.github.com> * Update packages/@aws-cdk/custom-resources/README.md Co-Authored-By: Jonathan Goldwasser <jogold@users.noreply.github.com> * Update packages/@aws-cdk/custom-resources/README.md Co-Authored-By: Jonathan Goldwasser <jogold@users.noreply.github.com> * Apply suggestions from code review Co-Authored-By: Jonathan Goldwasser <jogold@users.noreply.github.com> * add sdk-json to .gitignore * user-defined handlers are now passed as lambda.IFunction and make isComplete optional Instead of presuming to define the AWS Lambda function on behalf of the user, we now simply ask the user to supply a couple of IFunction objects. This gives users maximum flexibility in configuring their AWS Lambda environments. Furthermore, this change also makes isComplete optional and only defines the waiter resources in case isComplete is provided. Refactored integ test so that providers are deployed as a separate stack and their entrypoints are exported through CFN export names. * stop calling isComplete synchronously Since we now have a better way to represent that onEvent is synchronous (by simply not supplying an isComplete handler), and this will also result in a cleaner stack (no step functions, etc), the value of calling isComplete synchronously has been reduced. Combined with the observation by @jogold that the framework onEvent timeout would have to be user onEvent+isComplete, the complexity is not worth it. Also, refactor unit test harness such that it simulates the entire workflow (incl. reaction to startExecution and simulation of the waiter step function). * allow extensibility for CustomResourceProvider accept an interface instead of a class and use the `bind` pattern to allow defining resources as part of the provider. * simplify integration test (a single stack) * update README * code review fixes - remove validation of CFN event (not required) - redesign `failOnError` as `safeHandler` which returns a "safe" cloudformation handler. - fail if user handler returns a non-JSON response. * fix docstring in aws-cloudformation * set all framework timeouts to 15min later on we can figure out something smarter if need be * add a section about error handling * pass modules in topological order during packaging
- Loading branch information