Skip to content

Commit 4952f36

Browse files
authored
fix(redshift): enableRebootForParameterChanges fails synth with "cannot find entry file…" (#28760)
Error: ``` Error: Cannot find entry file at /node_modules/@aws-cdk/custom-resource-handlers/dist/ aws-redshift-alpha/asset-deployment-handler/index.js ``` This PR fixes the same issue detailed in #28658 but for `aws-redshift-alpha` as both modules have the same issue with accessing `custom-resource-handlers`. This PR uses the same airlift mechanism as `aws-cdk-lib` to move the necessary files into the `aws-redshift-alpha` package so its structure now looks like this: ``` |-- @aws-cdk |-- aws-redshift-alpha |-- custom-resource-handlers/dist/aws-redshift-alpha // airlifted in via this PR |-- custom-resource-handlers/dist |-- aws-redshift-alpha ``` The airlift script only moves the `index.js` file and not the `*/generated.ts` files because imports in alpha module `*/generated.ts` files do not currently work since the import paths were written to only support stable modules in `aws-cdk-lib`. I've tested the `aws-redshift-alpha` package locally on a local CDK app and confirmed the necessary structure exists in the packaged module. The local app calls the `cluster.enableRebootForParameterChanges()` method which creates the custom resource and I was able to verify that the cluster deploys properly and is rebootable. Related to #28633 but this is the fix for `aws-redshift-alpha` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b26e766 commit 4952f36

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

packages/@aws-cdk/aws-redshift-alpha/.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ junit.xml
2727
test/
2828
!*.lit.ts
2929
**/*.snapshot
30+
31+
# include custom-resource-handlers
32+
!custom-resource-handlers/*

packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ export class Cluster extends ClusterBase {
713713
const rebootFunction = new lambda.SingletonFunction(this, 'RedshiftClusterRebooterFunction', {
714714
uuid: '511e207f-13df-4b8b-b632-c32b30b65ac2',
715715
runtime: lambda.Runtime.NODEJS_18_X,
716-
code: lambda.Code.fromAsset(path.join(__dirname, '..', '..', 'custom-resource-handlers', 'dist', 'aws-redshift-alpha', 'cluster-parameter-change-reboot-handler')),
716+
code: lambda.Code.fromAsset(path.join(__dirname, '..', 'custom-resource-handlers', 'dist', 'aws-redshift-alpha', 'cluster-parameter-change-reboot-handler')),
717717
handler: 'index.handler',
718718
timeout: Duration.seconds(900),
719719
});

packages/@aws-cdk/aws-redshift-alpha/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@
6666
"cdk-build": {
6767
"env": {
6868
"AWSLINT_BASE_CONSTRUCT": true
69-
}
69+
},
70+
"pre": [
71+
"./scripts/airlift-custom-resource-handlers.sh"
72+
]
7073
},
7174
"keywords": [
7275
"aws",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
scriptdir=$(cd $(dirname $0) && pwd)
4+
customresourcedir=$(node -p "path.dirname(require.resolve('@aws-cdk/custom-resource-handlers/package.json'))")
5+
awscdklibdir=${scriptdir}/..
6+
7+
function airlift() {
8+
if [[ $1 != dist/core/nodejs-entrypoint-handler && ($1 = dist/core || $1 = dist/core/*) ]];
9+
then
10+
mkdir -p $awscdklibdir/core/lib/$1
11+
cp $customresourcedir/$2 $awscdklibdir/core/lib/$1
12+
else
13+
mkdir -p $awscdklibdir/custom-resource-handlers/$1
14+
cp $customresourcedir/$2 $awscdklibdir/custom-resource-handlers/$1
15+
fi
16+
}
17+
18+
recurse() {
19+
local dir=$1
20+
21+
for file in $dir/*; do
22+
if [ -f $file ]; then
23+
case $file in
24+
$customresourcedir/dist/aws-redshift-alpha/*/index.*)
25+
cr=$(echo $file | rev | cut -d "/" -f 2-4 | rev)
26+
airlift $cr $cr/index.*
27+
;;
28+
esac
29+
fi
30+
31+
if [ -d $file ]; then
32+
recurse $file
33+
fi
34+
done
35+
}
36+
37+
recurse $customresourcedir/dist

packages/@aws-cdk/custom-resource-handlers/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ and included as part of the `aws-cdk-lib` package.
1616
### Experimental:
1717

1818
- aws-amplify-alpha/asset-deployment-handler
19+
- aws-redshift-alpha/asset-deployment-handler
1920

2021
These handlers are excluded from `aws-cdk-lib/custom-resource-handlers` and are individually
2122
copied into their respective `-alpha` packages at build time. When an `-alpha` package is
2223
stabilized, part of the stabilization process **must** be to remove `-alpha` from the folder
2324
name, so that it is included in `aws-cdk-lib`.
2425

26+
`*/generated.ts` files are not supported for alpha modules due to import paths that only work for stable modules in `aws-cdk-lib`. These files must be added to `custom-resources-framework/config.ts` as `ComponentType.NO_OP`.
27+
2528
## Nodejs Entrypoint
2629

2730
This package also includes `nodejs-entrypoint.ts`, which is a wrapper that talks to

packages/@aws-cdk/custom-resource-handlers/lib/custom-resources-framework/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export const config: HandlerFrameworkConfig = {
226226
'aws-redshift-alpha': {
227227
'cluster-reboot-provider': [
228228
{
229-
type: ComponentType.SINGLETON_FUNCTION,
229+
type: ComponentType.NO_OP,
230230
sourceCode: path.resolve(__dirname, '..', 'aws-redshift-alpha', 'cluster-parameter-change-reboot-handler', 'index.ts'),
231231
},
232232
],

0 commit comments

Comments
 (0)