Skip to content

Commit

Permalink
fix(redshift): enableRebootForParameterChanges fails synth with "cann…
Browse files Browse the repository at this point in the history
…ot 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*
  • Loading branch information
paulhcsun authored Jan 19, 2024
1 parent b26e766 commit 4952f36
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ junit.xml
test/
!*.lit.ts
**/*.snapshot

# include custom-resource-handlers
!custom-resource-handlers/*
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ export class Cluster extends ClusterBase {
const rebootFunction = new lambda.SingletonFunction(this, 'RedshiftClusterRebooterFunction', {
uuid: '511e207f-13df-4b8b-b632-c32b30b65ac2',
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset(path.join(__dirname, '..', '..', 'custom-resource-handlers', 'dist', 'aws-redshift-alpha', 'cluster-parameter-change-reboot-handler')),
code: lambda.Code.fromAsset(path.join(__dirname, '..', 'custom-resource-handlers', 'dist', 'aws-redshift-alpha', 'cluster-parameter-change-reboot-handler')),
handler: 'index.handler',
timeout: Duration.seconds(900),
});
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-redshift-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
"cdk-build": {
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
},
"pre": [
"./scripts/airlift-custom-resource-handlers.sh"
]
},
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

scriptdir=$(cd $(dirname $0) && pwd)
customresourcedir=$(node -p "path.dirname(require.resolve('@aws-cdk/custom-resource-handlers/package.json'))")
awscdklibdir=${scriptdir}/..

function airlift() {
if [[ $1 != dist/core/nodejs-entrypoint-handler && ($1 = dist/core || $1 = dist/core/*) ]];
then
mkdir -p $awscdklibdir/core/lib/$1
cp $customresourcedir/$2 $awscdklibdir/core/lib/$1
else
mkdir -p $awscdklibdir/custom-resource-handlers/$1
cp $customresourcedir/$2 $awscdklibdir/custom-resource-handlers/$1
fi
}

recurse() {
local dir=$1

for file in $dir/*; do
if [ -f $file ]; then
case $file in
$customresourcedir/dist/aws-redshift-alpha/*/index.*)
cr=$(echo $file | rev | cut -d "/" -f 2-4 | rev)
airlift $cr $cr/index.*
;;
esac
fi

if [ -d $file ]; then
recurse $file
fi
done
}

recurse $customresourcedir/dist
3 changes: 3 additions & 0 deletions packages/@aws-cdk/custom-resource-handlers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ and included as part of the `aws-cdk-lib` package.
### Experimental:

- aws-amplify-alpha/asset-deployment-handler
- aws-redshift-alpha/asset-deployment-handler

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

`*/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`.

## Nodejs Entrypoint

This package also includes `nodejs-entrypoint.ts`, which is a wrapper that talks to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const config: HandlerFrameworkConfig = {
'aws-redshift-alpha': {
'cluster-reboot-provider': [
{
type: ComponentType.SINGLETON_FUNCTION,
type: ComponentType.NO_OP,
sourceCode: path.resolve(__dirname, '..', 'aws-redshift-alpha', 'cluster-parameter-change-reboot-handler', 'index.ts'),
},
],
Expand Down

0 comments on commit 4952f36

Please sign in to comment.