aws-amplify / aws-amplify/amplify-cli
Storage dependency undefined in custom resource on amplify init
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
22
### Amplify CLI Version
14.0.0
### What operating system are you using?
Amplify Hosting Default Linux
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made
### Describe the bug
When adding a dependency on storage to a custom CDK resource (Gen 1), the dependencies.storage is undefined when running amplify init in environment in Amplify Hosting CI/CD.
Example dependencies code
```
const dependencies = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[
{
category: 'storage',
resourceName: {files-resource-name}
},
]
)
```
This appears to be caused by custom resource being built BEFORE storage, so the storage dependency is undefined when you amplify init an environment without resources already built.
I didn't see this error when building locally because storage was already built locally when I added the custom resource and storage dependency was never undefined.
### Expected behavior
Adding a dependency on storage to a custom resource should not be undefined if storage isn't already built.
### Reproduction steps
1. Initialize new amplify project
2. Add storage/auth resources
3. Delete the build folders to simulate CI/CD environment
4. Add custom CDK resource
5. Add dependency on storage in cdk-stack.ts
6. Run amplify init
7. Storage dependency is undefined
### Project Identifier
I managed to get around this in my environment by returning if the storage dependency is undefined, but I don't have the issue with dependencies on API for example.
### Log output
```
# Put your logs below this line
2025-12-02T13:15:08.976Z [WARNING]: - Building resource auth/{resource-name}
304
2025-12-02T13:15:13.673Z [WARNING]: - Building resource auth/{resource-name}
305
2025-12-02T13:15:18.502Z [WARNING]: - Building resource custom/{resource-name}
306
2025-12-02T13:15:18.507Z [WARNING]: - Building custom resources
307
2025-12-02T13:15:30.881Z [WARNING]: - Building resource custom/{resource-name}
308
- Building custom resources
309
2025-12-02T13:15:40.607Z [WARNING]: - Building resource custom/{resource-name}
310
- Building custom resources
311
2025-12-02T13:15:50.742Z [WARNING]: ✖ Initializing your environment:{env-name}
312
2025-12-02T13:15:50.746Z [WARNING]: ✖ There was an error initializing your environment.
313
2025-12-02T13:15:50.746Z [INFO]: 🛑 There was an error building the custom resources
314
Cannot read properties of undefined (reading 'storage-resource-name')
```
### 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 by reproducing the failure with a new Amplify project, storage/auth resources, deleted build folders, and the dependency in cdk-stack.ts, then run amplify init. Trace the custom resource build relative to storage and inspect the undefined dependencies.storage value. Done means the storage dependency is available during initialization and the reported error no longer occurs in the CI/CD-like sequence.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- build-system, cli, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100