Skip to content

Commit 0f2b8f8

Browse files
authored
fix(amplify): addBranch fails synth with "cannot find entry file..." (#28658)
Error: ```bash Error: Cannot find entry file at /node_modules/@aws-cdk/custom-resource-handlers/dist/ aws-amplify-alpha/asset-deployment-handler/index.js ``` In #27955, we migrated the aws-amplify-alpha custom resource to `@aws-cdk/custom-resource-handlers`, our internal package for storing all custom resources. However, this migration was half-baked. The reason is because we seem to have depended on our `@aws-cdk/custom-resource-handlers` package directly. That works locally, as we have `custom-resource-handlers` readily available. ``` |-- @aws-cdk |-- aws-amplify-alpha |-- custom-resource-handlers ``` `aws-amplify-alpha` directly went into `custom-resource-handlers` to grab the necessary entry file. This works locally, because we have access to all folders with impunity. Of course, when packaged and published, we publish only `aws-amplify-alpha` with no other outside folders: ``` |-- @aws-cdk |-- aws-amplify-alpha ``` Thus, the published module would not have access to the file under `custom-resource-handlers`, and predictably fails at synth time. In `aws-cdk-lib`, we airlift the necessary files _into_ the package and release it alongside `aws-cdk-lib`: ``` |-- aws-cdk-lib |-- aws-synthetics |-- custom-resource-handlers/dist/aws-synthetics/custom-resource-handler // this was airlifted into aws-cdk-lib ``` We are supposed to do the same airlift mechanism for `aws-amplify-alpha` but somehow that was forgotten. This PR adds in the necessary structure, so now `aws-amplify-alpha` looks like this: ``` |-- @aws-cdk |-- aws-amplify-alpha |-- custom-resource-handlers/dist/aws-amplify-alpha // airlifted in via this PR |-- custom-resource-handlers/dist |-- aws-amplify-alpha ``` (please excuse my horrible ascii notation) Fixes #28633. Fixes #28089. I tested my locally packaged `aws-amplify-alpha` on a local CDK app to confirm that the necessary structure exists in the packaged module. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 66c1109 commit 0f2b8f8

23 files changed

+291
-87
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ junit.xml
3131
test/
3232
!*.lit.ts
3333
**/*.snapshot
34+
35+
# include custom-resource-handlers
36+
!custom-resource-handlers/*

packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class AmplifyAssetDeploymentProvider extends NestedStack {
233233
this,
234234
'amplify-asset-deployment-on-event',
235235
{
236-
entry: path.join(__dirname, '..', '..', 'custom-resource-handlers', 'dist', 'aws-amplify-alpha', 'asset-deployment-handler', 'index.js'),
236+
entry: path.join(__dirname, '..', 'custom-resource-handlers', 'dist', 'aws-amplify-alpha', 'asset-deployment-handler', 'index.js'),
237237
handler: 'onEvent',
238238
initialPolicy: [
239239
new iam.PolicyStatement({

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767
"cdk-build": {
6868
"env": {
6969
"AWSLINT_BASE_CONSTRUCT": true
70-
}
70+
},
71+
"pre": [
72+
"./scripts/airlift-custom-resource-handlers.sh"
73+
]
7174
},
7275
"keywords": [
7376
"aws",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
list_custom_resources() {
8+
for file in $customresourcedir/dist/aws-amplify-alpha/*/index.js; do
9+
echo $file | rev | cut -d "/" -f 2-4 | rev
10+
done
11+
}
12+
13+
customresources=$(list_custom_resources)
14+
15+
echo $customresources
16+
17+
cd $awscdklibdir
18+
mkdir -p $awscdklibdir/custom-resource-handlers
19+
20+
for cr in $customresources; do
21+
mkdir -p $awscdklibdir/custom-resource-handlers/$cr
22+
cp $customresourcedir/$cr/index.js $awscdklibdir/custom-resource-handlers/$cr
23+
done

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.js.snapshot/asset.85f7bb0ac0b4da3571afd49c891d631f4f07c0ef710a02046d3a9abd8d9d4604/index.js

+110
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.js.snapshot/cdk-amplify-app-asset-deployment.assets.json

+17-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.js.snapshot/cdk-amplify-app-asset-deployment.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
{
9191
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
9292
},
93-
"/d1af98ce124bb93199d3d45ff8930b99badcdd089777b7976a0ad9af56d220f6.json"
93+
"/2f9d2632b48a4f92f6691c3e3cfcbeb47798c945a2d03b93514de1a3d3ec72ed.json"
9494
]
9595
]
9696
}

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.js.snapshot/cdkamplifyappassetdeploymentcomamazonawscdkcustomresourcesamplifyassetdeploymentprovider02396C99.nested.template.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"S3Bucket": {
6565
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
6666
},
67-
"S3Key": "9307ab790c544d7c4d94504a1c950222bbfc119c2c12b44440ad46939e0b6364.zip"
67+
"S3Key": "85f7bb0ac0b4da3571afd49c891d631f4f07c0ef710a02046d3a9abd8d9d4604.zip"
6868
},
6969
"Environment": {
7070
"Variables": {

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.js.snapshot/manifest.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-asset-deployment.js.snapshot/tree.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-codecommit.js.snapshot/cdk-amplify-codecommit-app.assets.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-codecommit.js.snapshot/cdk-amplify-codecommit-app.template.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"AppF1B96344": {
5353
"Type": "AWS::Amplify::App",
5454
"Properties": {
55-
"Name": "App",
5655
"BasicAuthConfig": {
5756
"EnableBasicAuth": false
5857
},
@@ -62,13 +61,14 @@
6261
"Arn"
6362
]
6463
},
64+
"Name": "App",
65+
"Platform": "WEB",
6566
"Repository": {
6667
"Fn::GetAtt": [
6768
"Repo02AC86CF",
6869
"CloneUrlHttp"
6970
]
70-
},
71-
"Platform": "WEB"
71+
}
7272
}
7373
},
7474
"AppmainF505BAED": {
@@ -120,4 +120,4 @@
120120
]
121121
}
122122
}
123-
}
123+
}

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-codecommit.js.snapshot/cdk.out

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-codecommit.js.snapshot/integ.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/aws-amplify-alpha/test/integ.app-codecommit.js.snapshot/manifest.json

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)