aws-amplify / aws-amplify/amplify-cli
Hosting CI/CD fails due to custom resource depending on storage
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
pnpm
### If applicable, what version of Node.js are you using?
20
### Amplify CLI Version
12.10.1
### What operating system are you using?
Mac
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No
### Describe the bug
https://github.com/aws-amplify/amplify-hosting/issues/2478
^^
This bug is still a thing, in January 2024. Locally, I am able to build/push a custom CDK resource that contains this:
```
const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[
{
category: "storage",
resourceName: "myprojectV2DevelopStorage"
},
]
);
const bucketName = cdk.Fn.ref(dependencies.storage.myprojectV2DevelopStorage.BucketName)
const bucket = s3.Bucket.fromBucketName(this, bucketName, bucketName);
```
but in the Amplify CI/CD pipeline, this fails miserably with the error:
```
Command failed with exit code 2: /codebuild/output/src2150635331/src/myproject-v2/amplify/backend/custom/hcV2CDN/node_modules/.bin/tsc
cdk-stack.ts(57,48): error TS2339: Property 'storage' does not exist on type 'AmplifyDependentResourcesAttributes'.
```
And just like in the comments for the GitHub issue...this appears to work:
```
const bktNotBad = cdk.Fn.ref('storagemyprojectV2DevelopStorageBucketName')
```
### Expected behavior
Following the Amplify docs and instructions generated by the CLI and in the docs, I'd expect to be able to use this pattern, without my builds breaking, inexplicably.
```ts
const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[
{
category: "storage",
resourceName: "myprojectV2DevelopStorage"
},
]
);
const bucketName = cdk.Fn.ref(dependencies.storage.myprojectV2DevelopStorage.BucketName)
const bucket = s3.Bucket.fromBucketName(this, bucketName, bucketName);
```
### Reproduction steps
1. add storage to your project
2. add a custom CDK resource to your project
3. follow the instructions and documentation by doing this in your CDK resource:
```ts
const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[
{
category: "storage",
resourceName: "myprojectV2DevelopStorage"
},
]
);
const bucketName = cdk.Fn.ref(dependencies.storage.myprojectV2DevelopStorage.BucketName)
const bucket = s3.Bucket.fromBucketName(this, bucketName, bucketName);
```
4. `amplify push` --> everything works
5. set up CI/CD on your project
6. `git push`
7. Observe your CI/CD pipeline break/fail
8. Change the code to this:
```ts
const bktNotBad = cdk.Fn.ref('storagemyprojectV2DevelopStorageBucketName')
// const bucketName = cdk.Fn.ref(dependencies.storage.myprojectV2DevelopStorage.BucketName)
const bucket = s3.Bucket.fromBucketName(this, bktNotBad, bktNotBad);
```
9. Watch it work.
### Project Identifier
e800fd03f8e9a7692235717d7b1bf9d4
### Log output
```
# Put your logs below this line
```
### Additional information
_No response_
### Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Contributor guide
Research direction
Start with the custom resource's cdk-stack.ts and the AmplifyHelpers.addResourceDependency call shown in the report. Compare the generated dependency typings and TypeScript build between local amplify push and the CI/CD pipeline, then run the custom resource's tsc command; done means the documented storage dependency pattern compiles and the pipeline succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, typescript
- Domain
- ci-cd, cli, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100