Hosting CI/CD fails due to custom resource depending on storage
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.
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
- add storage to your project
- add a custom CDK resource to your project
- follow the instructions and documentation by doing this in your CDK resource:
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);
amplify push--> everything works- set up CI/CD on your project
git push- Observe your CI/CD pipeline break/fail
- Change the code to this:
const bktNotBad = cdk.Fn.ref('storagemyprojectV2DevelopStorageBucketName')
// const bucketName = cdk.Fn.ref(dependencies.storage.myprojectV2DevelopStorage.BucketName)
const bucket = s3.Bucket.fromBucketName(this, bktNotBad, bktNotBad);
- 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.
Hey @armenr, thank you for reaching out. The issue does look similar to https://github.com/aws-amplify/amplify-cli/issues/11847, referring to the comment https://github.com/aws-amplify/amplify-cli/issues/11847#issuecomment-1489013184 it appears a fix was released on CLI v11.0.3. If the issues does not occur locally and occurs on CICD, does the console app use a live package override that ties Amplify CLI to an older version or install on the yml file?
@ykethan - I am installing the latest CLI package using both the override, as well as a manual install command in my amplify.yml
@armenr, thank you for the information. I was able to reproduce the issue, marking as bug. possible workarounds: https://github.com/aws-amplify/amplify-cli/issues/11847#issuecomment-1428861075 and https://github.com/aws-amplify/amplify-cli/issues/11847#issuecomment-1464094946
Thanks for the quick turn-around on investigating this, and for confirmation that we're not crazy 😂 .
I'll try the workaround and report back, but for now, this approach const bucketName = cdk.Fn.ref('storagemyProjectV2DevelopStorageBucketName') seems to be working as well.
I'll experiment if I have free time and report back.
I can confirm that this workaround https://github.com/aws-amplify/amplify-cli/issues/11847#issuecomment-1464094946 , reordering config-backend.json, does work.
That workaround is unreliable - the json may get reordered or regenerated without warning.
Any updates on this ?
Just dropped in to see what condition our condition is in... :)
Our team is facing this issue. Any update?