Skip to content

Commit

Permalink
fix(amplify): addBranch fails synth with "cannot find entry file..." (#…
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
kaizencc authored Jan 16, 2024
1 parent 66c1109 commit 0f2b8f8
Show file tree
Hide file tree
Showing 23 changed files with 291 additions and 87 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-amplify-alpha/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ junit.xml
test/
!*.lit.ts
**/*.snapshot

# include custom-resource-handlers
!custom-resource-handlers/*
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-amplify-alpha/lib/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class AmplifyAssetDeploymentProvider extends NestedStack {
this,
'amplify-asset-deployment-on-event',
{
entry: path.join(__dirname, '..', '..', 'custom-resource-handlers', 'dist', 'aws-amplify-alpha', 'asset-deployment-handler', 'index.js'),
entry: path.join(__dirname, '..', 'custom-resource-handlers', 'dist', 'aws-amplify-alpha', 'asset-deployment-handler', 'index.js'),
handler: 'onEvent',
initialPolicy: [
new iam.PolicyStatement({
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-amplify-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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,23 @@
#!/bin/bash

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

list_custom_resources() {
for file in $customresourcedir/dist/aws-amplify-alpha/*/index.js; do
echo $file | rev | cut -d "/" -f 2-4 | rev
done
}

customresources=$(list_custom_resources)

echo $customresources

cd $awscdklibdir
mkdir -p $awscdklibdir/custom-resource-handlers

for cr in $customresources; do
mkdir -p $awscdklibdir/custom-resource-handlers/$cr
cp $customresourcedir/$cr/index.js $awscdklibdir/custom-resource-handlers/$cr
done

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 @@ -90,7 +90,7 @@
{
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"/d1af98ce124bb93199d3d45ff8930b99badcdd089777b7976a0ad9af56d220f6.json"
"/2f9d2632b48a4f92f6691c3e3cfcbeb47798c945a2d03b93514de1a3d3ec72ed.json"
]
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "9307ab790c544d7c4d94504a1c950222bbfc119c2c12b44440ad46939e0b6364.zip"
"S3Key": "85f7bb0ac0b4da3571afd49c891d631f4f07c0ef710a02046d3a9abd8d9d4604.zip"
},
"Environment": {
"Variables": {
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.

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 @@ -52,7 +52,6 @@
"AppF1B96344": {
"Type": "AWS::Amplify::App",
"Properties": {
"Name": "App",
"BasicAuthConfig": {
"EnableBasicAuth": false
},
Expand All @@ -62,13 +61,14 @@
"Arn"
]
},
"Name": "App",
"Platform": "WEB",
"Repository": {
"Fn::GetAtt": [
"Repo02AC86CF",
"CloneUrlHttp"
]
},
"Platform": "WEB"
}
}
},
"AppmainF505BAED": {
Expand Down Expand Up @@ -120,4 +120,4 @@
]
}
}
}
}

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.

Loading

0 comments on commit 0f2b8f8

Please sign in to comment.