Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hosting CI/CD fails due to custom resource depending on storage #13532

Open
2 tasks done
armenr opened this issue Jan 13, 2024 · 9 comments
Open
2 tasks done

Hosting CI/CD fails due to custom resource depending on storage #13532

armenr opened this issue Jan 13, 2024 · 9 comments
Labels
bug Something isn't working custom-cdk Issues related to custom CDK resource functionality hosting Issues tied to hosting category p2

Comments

@armenr
Copy link

armenr commented Jan 13, 2024

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

aws-amplify/amplify-hosting#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

  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:
    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);
  1. amplify push --> everything works
  2. set up CI/CD on your project
  3. git push
  4. Observe your CI/CD pipeline break/fail
  5. 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);
  1. Watch it work.

Project Identifier

e800fd03f8e9a7692235717d7b1bf9d4

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@ykethan
Copy link
Member

ykethan commented Jan 16, 2024

Hey @armenr, thank you for reaching out. The issue does look similar to #11847, referring to the comment #11847 (comment) 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 ykethan added hosting Issues tied to hosting category custom-cdk Issues related to custom CDK resource functionality pending-response Issue is pending response from the issue author labels Jan 16, 2024
@armenr
Copy link
Author

armenr commented Jan 16, 2024

@ykethan - I am installing the latest CLI package using both the override, as well as a manual install command in my amplify.yml

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jan 16, 2024
@ykethan
Copy link
Member

ykethan commented Jan 17, 2024

@armenr, thank you for the information. I was able to reproduce the issue, marking as bug.
possible workarounds: #11847 (comment) and #11847 (comment)

@ykethan ykethan added bug Something isn't working regression Flair label to track regressions and removed pending-triage Issue is pending triage labels Jan 17, 2024
@armenr
Copy link
Author

armenr commented Jan 17, 2024

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.

@josefaidt josefaidt added p2 and removed regression Flair label to track regressions labels Jan 30, 2024
@josefaidt josefaidt changed the title Unresolved Bug from 2022 Is Still a Problem in 2024 Hosting CI/CD fails due to custom resource depending on storage Jan 30, 2024
@johnf
Copy link
Contributor

johnf commented Feb 2, 2024

I can confirm that this workaround #11847 (comment) , reordering config-backend.json, does work.

@armenr
Copy link
Author

armenr commented Feb 2, 2024

That workaround is unreliable - the json may get reordered or regenerated without warning.

@hasadata
Copy link

hasadata commented Mar 2, 2024

Any updates on this ?

@armenr
Copy link
Author

armenr commented Mar 19, 2024

Just dropped in to see what condition our condition is in... :)

@Zhuohui-Li
Copy link

Our team is facing this issue. Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working custom-cdk Issues related to custom CDK resource functionality hosting Issues tied to hosting category p2
Projects
None yet
Development

No branches or pull requests

6 participants