Skip to content

Commit

Permalink
feat: implement node runtime region awareness for cdk vended custom r…
Browse files Browse the repository at this point in the history
…esources (aws#30108)

This PR introduces node runtime region awareness into the custom resource provider framework by doing the following:

- Adding a `LATEST_NODE_RUNTIME_MAP` fact table used to maintain the latest node runtime available per AWS partition
- Introducing `determineLatestNodeRuntime` and `determineLatestNodeRuntimeName` functions which determine the latest Lambda node `Runtime` and the latest Lambda node `Runtime` name, respectively
- Updating the custom resource provider framework to utilize these two functions when code generating the runtime property for providers using node runtimes

This PR can be segmented into the following code changes:

- A `LATEST_NODE_RUNTIME_MAP` fact table was added which maintains the latest Lambda node runtime available per AWS partition.
- Introduced `determineLatestNodeRuntime` and `determineLatestNodeRuntimeName` functions which determine the latest Lambda node `Runtime` and the latest Lambda node `Runtime` name, respectively.
- The existing runtime property being code generated via the custom resource provider framework has been altered to now use the appropriate runtime determiner function, i.e., `determineLatestNodeRuntimeName` for `CustomResourceProvider` or `determineLatestNodeRuntime` for `Function` or `SingletonFunction`. Any custom resource provider using a python runtime will not use either of these functions.
- To consolidate and manage importing of external modules a `ModuleImporter` class has been created. This class allows external modules to be registered as an import for a target module and prevents duplicate imports for modules that contain multiple framework components. This class also provides the ability to specify different import paths which allows all external modules to be consolidated into a single class rather than having duplicate external modules defined for different import paths. Lastly, this class determines whether or not external modules should be imported selectively or if all targets in the external module should be imported under an alias, i.e., `import { Function } from 'aws-lambda'` vs. `import * as lambda from 'aws-lambda'`
- A `CallableExpr` class was created to allow expression proxies to be created from a specified expression name. This allows the new runtime determiner functions and other module specific functions to be called from their specified module and built into a JavaScript object that will mirror the JavaScript operations done to it in an expression tree.

Manually tested all individual custom resource handlers for create, update, and delete. I verified that the behavior seen was what was expected based off of the handler code. All impacted integ tests were updated. New unit tests were added to the custom resource handler framework to test that generated code correctly included `determineLatestNodeRuntime` for Lambda based handlers and `determineLatestNodeRuntimeName` for `CfnResource` based handlers. Added new unit tests to test the functionality of `determineLatestNodeRuntime` and `determineLatestNodeRuntimeName` for region agnostic stacks, stacks in commercial region, stacks in China regions, stacks in ADC regions, and stacks in GovCloud regions.

- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
colifran authored and pahud committed Jun 12, 2024
1 parent 364f86b commit 74bcc1f
Show file tree
Hide file tree
Showing 1,260 changed files with 496,941 additions and 520,579 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "2ec8ad9e91dcd6e7ad6a5c84ffc6c9c05c408aca3b26ceb2816d81043e6c4dc3.zip"
"S3Key": "96ea260348625427bb7f28ab3b379f62da6f428bcd155cb13f9261aa6a404b0d.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand All @@ -124,7 +124,15 @@
"Arn"
]
},
"Runtime": "nodejs18.x",
"Runtime": {
"Fn::FindInMap": [
"LatestNodeRuntimeMap",
{
"Ref": "AWS::Region"
},
"value"
]
},
"Description": {
"Fn::Join": [
"",
Expand Down Expand Up @@ -290,6 +298,115 @@
}
}
},
"Mappings": {
"LatestNodeRuntimeMap": {
"af-south-1": {
"value": "nodejs20.x"
},
"ap-east-1": {
"value": "nodejs20.x"
},
"ap-northeast-1": {
"value": "nodejs20.x"
},
"ap-northeast-2": {
"value": "nodejs20.x"
},
"ap-northeast-3": {
"value": "nodejs20.x"
},
"ap-south-1": {
"value": "nodejs20.x"
},
"ap-south-2": {
"value": "nodejs20.x"
},
"ap-southeast-1": {
"value": "nodejs20.x"
},
"ap-southeast-2": {
"value": "nodejs20.x"
},
"ap-southeast-3": {
"value": "nodejs20.x"
},
"ap-southeast-4": {
"value": "nodejs20.x"
},
"ca-central-1": {
"value": "nodejs20.x"
},
"cn-north-1": {
"value": "nodejs18.x"
},
"cn-northwest-1": {
"value": "nodejs18.x"
},
"eu-central-1": {
"value": "nodejs20.x"
},
"eu-central-2": {
"value": "nodejs20.x"
},
"eu-north-1": {
"value": "nodejs20.x"
},
"eu-south-1": {
"value": "nodejs20.x"
},
"eu-south-2": {
"value": "nodejs20.x"
},
"eu-west-1": {
"value": "nodejs20.x"
},
"eu-west-2": {
"value": "nodejs20.x"
},
"eu-west-3": {
"value": "nodejs20.x"
},
"il-central-1": {
"value": "nodejs20.x"
},
"me-central-1": {
"value": "nodejs20.x"
},
"me-south-1": {
"value": "nodejs20.x"
},
"sa-east-1": {
"value": "nodejs20.x"
},
"us-east-1": {
"value": "nodejs20.x"
},
"us-east-2": {
"value": "nodejs20.x"
},
"us-gov-east-1": {
"value": "nodejs18.x"
},
"us-gov-west-1": {
"value": "nodejs18.x"
},
"us-iso-east-1": {
"value": "nodejs18.x"
},
"us-iso-west-1": {
"value": "nodejs18.x"
},
"us-isob-east-1": {
"value": "nodejs18.x"
},
"us-west-1": {
"value": "nodejs20.x"
},
"us-west-2": {
"value": "nodejs20.x"
}
}
},
"Outputs": {
"MyApiEndpoint869ABE96": {
"Value": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74bcc1f

Please sign in to comment.