-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement code generated handler framework #28251
Merged
Merged
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
b983212
initial commit - framework, classes, constructors, modules
colifran 7145c7a
refactor
colifran dd2ff42
refactor and bug fixes
colifran f7b4593
initial setup for config file
colifran 2038bcf
updated outfile location and config format
colifran d888a5d
Merge branch 'main' into colifran/codegen-handler-framework
colifran c87613b
initial work on build script
colifran 6de2be2
refactor
colifran 5873fe4
migrated handler framework into custom resource handlers and updated …
colifran dccc985
migrated handler-framework into custom-resource-handlers
colifran 688a69d
imports for external modules
colifran c920b1e
refactored airlift custom resource handlers
colifran c78566a
formatting
colifran 0f8c8e5
exclude dist from compilation
colifran 00fc75a
code to generate custom super props
colifran ba9c570
path import and path literal in config
colifran 3f450da
remove cdk handler and runtime determiner
colifran ba044b6
compatible framework runtimes
colifran 43e60d7
singleton interface creation
colifran 8ef2e15
refactor for generate script
colifran 7ef5139
removed unneeded console log
colifran 0c45784
added to config
colifran 1647a82
no op
colifran 7da55a3
config
colifran 2210613
refactor for cdk handler changes and added immutable to property spec…
colifran 9d950d9
cdk-handler and runtime determiner
colifran e19f090
get or create cdk handler to force singleton cdk handler and migration
colifran 6712a4e
merge conflicts
colifran fd0b93f
refactor for cdk handler change and updated config
colifran bacd7b6
move runtime determiner and create runtime class to break circular de…
colifran ca3be84
renamed to custom resource framework
colifran 721c59f
migrate
colifran f2504ae
refactor
colifran 98cbe11
migrate
colifran aa3c176
migrate to codegen providers
colifran c89f470
airlift core to core
colifran b0e9ba4
core internal
colifran d6d5cbf
finished migrating core providers
colifran ca0ad0a
reverted drain hook change
colifran 2ca1f33
use lambda runtime and auto generate component name
colifran e036649
lambda runtime isdeprecated flag
colifran b8da22d
generate names better
colifran 13a0b48
formatting
colifran 1496b55
update custom resources to use auto generated names
colifran 972836b
remove console log
colifran 7b87231
drain hook revert
colifran c4a20ba
runtimes determiner testing
colifran 510bcaa
testing and empty readme
colifran a7b74e1
alpha
colifran 228aafd
runtime deprecated
colifran c3fdb61
naming
colifran 187c7df
refactor and naming update
colifran f857264
naming
colifran 2db1c20
docstring
colifran 3c81f54
fix framework unit tests
colifran cc69345
fix failures
colifran 034c7ce
unit tests
colifran 7ba9f86
selective import from core internal stack module
colifran 1db5e8c
formatting
colifran c11b42a
update importing modules
colifran 3744d65
documentation
colifran a64afe4
readme and naming
colifran 3a8757a
readme
colifran 7a326ca
fix unit tests
colifran 8582ad6
Merge branch 'main' into colifran/codegen-handler-framework
colifran cb75044
Merge branch 'main' into colifran/codegen-handler-framework
colifran 812ac0a
naming
colifran 7b3e7c1
name generator
colifran cf435a0
updated generated component names
colifran 4d25941
fixed unit tests with new naming
colifran e8f5a3a
reverted lambda runtime deprecated flag
colifran 46aa221
fix constructor props
colifran ab259ed
node18 as esbuild target
colifran 11f9476
readme
colifran f77cacf
readme
colifran dedc574
utils tests
colifran 2dffd0a
Merge branch 'main' into colifran/codegen-handler-framework
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
readme and naming
Signed-off-by: Francis <colifran@amazon.com>
- Loading branch information
commit a64afe4c7914eb01fdc7ed941c61eba96a5bff8a
There are no files selected for viewing
56 changes: 53 additions & 3 deletions
56
...ages/@aws-cdk/custom-resource-handlers/lib/custom-resources-framework/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,58 @@ | ||
# AWS CDK Custom Resource Framework | ||
|
||
The CDK custom resource framework is an internal framework developed to establish best practices, runtime enforcement, and consistency for custom resource providers and their associated handler code. | ||
The CDK custom resource framework is an internal framework developed to establish best practices, runtime enforcement, and consistency for custom resource providers and their associated source code. | ||
|
||
# Creating a Custom Resource Provider | ||
|
||
Custom resource providers can be created in one of three forms - `CdkFunction`, `CdkSingletonFunction`, or `CdkCustomResourceProvider`. These three custom resource provider formats are a code generated wrapper around the lambda `Function`, lambda `SingletonFunction`, and `CustomResourceProvider` constructs, respectively. These new CDK prefixed constructs will offer the same behavior and construction options as their parent minus the ability to configure the `handler`, `code`, `runtime`, and `runtimeName` properties during construction. Instead, `handler`, `code`, `runtime`, and `runtimeName` will be automatically generated using the properties configured in the [config](./config.ts) file. The [config](./config.ts) file is structured with the top most level mapping to a specific service, i.e., `aws-s3`, `aws-dynamodb`, etc. Each service can contain one or more provider modules which are containers for the custom resource providers being requested. Custom resource providers are defined within a provider module as an array of one or more `ConfigProps`. `ConfigProps` allow you to define a provider with the following properties: | ||
- type: the | ||
Custom resource providers can be created in one of three forms - `CdkFunction`, `CdkSingletonFunction`, or `CdkCustomResourceProvider`. These three custom resource provider formats are a code generated wrapper around the lambda `Function`, lambda `SingletonFunction`, and `CustomResourceProvider` constructs, respectively. These new CDK prefixed constructs will offer the same behavior and initialization options as their parent minus the ability to configure the following properties during construction: | ||
- `handler` - the name of the method within your code that the provider calls to execute your function | ||
- `code` - the source code of your provider | ||
- `codeDirectory` - a local file system directory with the provider's code | ||
- `runtime` - the runtime environment for the provider that you are uploading | ||
|
||
Instead, these properties will be automatically generated using the `ProviderProps` configured in the [config](./config.ts) file: | ||
- `type`: the custom resource provider type to generate | ||
- `sourceCode`: the source code that will be executed by the provider | ||
- `compatibleRuntimes`: runtimes that are compatible with the provider's source code | ||
- `handler`: the name of the method within your code that the provider calls to execute your function | ||
|
||
The [config](./config.ts) file is structured with the top most level mapping to a specific service, i.e., `aws-s3`, `aws-dynamodb`, etc. Each service can contain one or more provider modules. Provider modules are containers for custom resource providers and will be rendered as a code generated file. Each provider module can contain one or more `ProviderProps` objects. Each `ProviderProps` object contains all the necessary information required to generate a single custom resource provider. For more clarity, consider the following example of the [config](./config.ts) file: | ||
|
||
```ts | ||
const config = { | ||
'aws-certificatemanager': { | ||
'certificate-request-provider': [ | ||
{ | ||
type: ComponentType.CDK_FUNCTION, | ||
sourceCode: path.resolve(__dirname, '..', 'aws-certificatemanager' 'dns-validated-certificate-handler', 'index.js'), | ||
compatibleRuntimes: [Runtime.NODEJS_18_X], | ||
handler: 'index.certificateRequestHandler', | ||
}, | ||
], | ||
}, | ||
'aws-s3': { | ||
'replica-provider': [ | ||
{ | ||
type: ComponentType.CDK_FUNCTION, | ||
sourceCode: path.resolve(__dirname, '..', 'aws-dynamodb', 'replica-handler', 'index.ts'), | ||
compatibleRuntimes: [Runtime.NODEJS_18_X], | ||
handler: 'index.onEventHandler', | ||
}, | ||
{ | ||
type: ComponentType.CDK_FUNCTION, | ||
sourceCode: path.resolve(__dirname, '..', 'aws-dynamodb', 'replica-handler', 'index.ts'), | ||
compatibleRuntimes: [Runtime.NODEJS_18_X], | ||
handler: 'index.isCompleteHandler', | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
|
||
Inspecting the above example gives us the following information: | ||
- There are two services present: `aws-certificatemanager` and `aws-s3` | ||
- Both the `aws-certificatemanager` and `aws-dynamodb` services contain a single provider module - `certificate-request-provider` and `replica-provider`, respectively | ||
- The `certificate-request-provider` contains a single custom resource provider which is a `CdkFunction` | ||
- The `replica-provider` provider module contains two custom resource providers both of which are `CdkFunction` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This framing around
CdkFunction
,CdkSingletonFunction
etc is confusing me a little.As far as I can tell, those exact classes are gone (which is great!) so now these are just concepts. That's fine, but as a concept a
CdkFunction
doesn't really mean anything to me.Can we not give these names after what you would use them for:
CdkFunction
->BuiltinLambdaFunction
(because I think these are never used as custom resource providers?)SingletonFunction
-> actually confusing to me. Are these usually/always used for custom resource providers? Or no? Are they also built-in Lambda functions that are not actually used as custom resource providers? If true, the naming of this section is confusing, because you're heavily stating it's all about custom resources everywhere, but it might not actually be? Maybe it's just non-Custom Resource Lambdas we provision for you?CdkCustomResourceProvider
-> this should make a distinction between thecore.CustomResourceProvider
and thecustom-resources.CustomResourceProvider
. Maybe name them something likeCoreCustomResource
andLongStabilizationCustomResource
?Maybe the flavors of Lambdas we generate here are:
RuntimeLambda({ singleton: boolean })
CoreCustomResource
LongStabilizationCustomResource({ onEvent, isComplete })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm a little worried we're only adding more layers of indirection, and it looks like we're only adding complexity instead of taking it away...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(If
CdkFunction
,CdkSingletonFunction
etc are still in from the previous commit, then I think we can take them out again, and we can just codegen their implementations)