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

feat(amplify): Add Amplify asset deployment resource #16922

Merged
merged 12 commits into from
Dec 14, 2021
Merged

Conversation

samkio
Copy link
Contributor

@samkio samkio commented Oct 12, 2021

This change adds a custom resource that allows users
to publish S3 assets to AWS Amplify.

fixes #16208


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 12, 2021

@samkio
Copy link
Contributor Author

samkio commented Oct 12, 2021

Build currently fails with:

@aws-cdk/aws-amplify-alpha: �[96mlib/asset-deployment-handler/common.ts
�[0m:�[93m4�[0m:�[93m8�[0m - �[91merror�[0m�[90m TS2307: �[0mCannot find module 'aws-cdk-lib/custom-resources/lib/provider-framework/types' or its corresponding type declarations.
@aws-cdk/aws-amplify-alpha: �[7m4�[0m } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';
@aws-cdk/aws-amplify-alpha: �[7m �[0m �[91m       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
@aws-cdk/aws-amplify-alpha: �[96mlib/asset-deployment-handler/handler.ts�
[0m:�[93m4�[0m:�[93m8�[0m - �[91merror�[0m�[90m TS2307: �[0mCannot find module 'aws-cdk-lib/custom-resources/lib/provider-framework/types' or its corresponding type declarations.
@aws-cdk/aws-amplify-alpha: �[7m4�[0m } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';
@aws-cdk/aws-amplify-alpha: �[7m �[0m �[91m       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m

Which I added as a dependency. It worked locally too... 😕
I followed the same structure as aws-eks (https://github.com/samkio/aws-cdk/blob/42d43db12bc2ee7cf254424f41571348f8cd6222/packages/@aws-cdk/aws-eks/lib/cluster-resource-handler/common.ts#L2) which has the same import.

@samkio samkio force-pushed the master branch 3 times, most recently from 03a7ebe to 622fa23 Compare October 13, 2021 15:32
@MrArnoldPalmer MrArnoldPalmer added effort/small Small work item – less than a day of effort p1 labels Oct 13, 2021
@peterwoodworth peterwoodworth changed the title feat(amplify): Add Amplify asset deployment resource feat(amplify): Add Amplify asset deployment resource Oct 21, 2021
@github-actions github-actions bot added the @aws-cdk/aws-amplify Related to AWS Amplify label Oct 21, 2021
@skinny85
Copy link
Contributor

@samkio would you mind updating your PR with the latest master? I want to see if the build succeeds or fails.

Thanks,
Adam

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting in "Request changes" to clear this one from my To-Do list. @samkio please re-request my review when this is ready!

@samkio
Copy link
Contributor Author

samkio commented Oct 24, 2021

@skinny85 can you share the docs on what AWS CodeBuild us-east-1 (AutoBuildProject89A8053A-LhjRyN9kxr8o) — Build failed for project AutoBuildProject89A8053A-LhjRyN9kxr8o does? I am starting to lose hope in this change. Everything works fine locally but fails in this CodeBuild step. Now it complains about the hashes being different.

Running locally however:

Verifying integ.app-asset-deployment.js against integ.app-asset-deployment.expected.json ... OK.
Verifying integ.app-codecommit.js against integ.app-codecommit.expected.json ... OK.
Verifying integ.app.js against integ.app.expected.json ... OK.
Tests successful. Total time (7.3s) | /home/samkio/projects/aws-cdk/node_modules/jest/bin/jest.js (5.0s) | cdk-integ-assert (2.2s)

Integrations are taking longer as I can't try locally; I have to push and see CodeBuild fail. Any help will be appreciated.

@samkio samkio requested a review from skinny85 October 24, 2021 16:34
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skinny85 can you share the docs on what AWS CodeBuild us-east-1 (AutoBuildProject89A8053A-LhjRyN9kxr8o) — Build failed for project AutoBuildProject89A8053A-LhjRyN9kxr8o does? I am starting to lose hope in this change. Everything works fine locally but fails in this CodeBuild step. Now it complains about the hashes being different.

Running locally however:

Verifying integ.app-asset-deployment.js against integ.app-asset-deployment.expected.json ... OK.
Verifying integ.app-codecommit.js against integ.app-codecommit.expected.json ... OK.
Verifying integ.app.js against integ.app.expected.json ... OK.
Tests successful. Total time (7.3s) | /home/samkio/projects/aws-cdk/node_modules/jest/bin/jest.js (5.0s) | cdk-integ-assert (2.2s)

Integrations are taking longer as I can't try locally; I have to push and see CodeBuild fail. Any help will be appreciated.

Hey @samkio! Don't give up, you'r extremely close 🙂. They're a simple change you can make to your integ test that should make the build pass - I've included it in my review.

This change adds a custom resource that allows users
to publish S3 assets to AWS Amplify.

fixes aws#16208
@MrArnoldPalmer
Copy link
Contributor

@samkio I've been playing with this locally and have gotten it to work against a v1 app. Since Amplify is marked as stable and included in aws-cdk-lib, I think we should actually merge this as a new experimental module so users know there may be changes to the API and/or behavior of the custom resource if needed.

To do this we will have to create a new package in packages/@aws-cdk that has stability experimental. This will automatically release as a separate package with -alpha appended to the name. I'm asking around for guidance on the best way to do this, IE what to name this module etc. As far as I can tell, it would be fairly easy to decouple this from the existing App construct and instead do something like new AmplifyAssetsDeploy(this, 'scope', myAmplifyApp) to create the custom resource.

What do you think about that?

@samkio
Copy link
Contributor Author

samkio commented Dec 13, 2021

@samkio I've been playing with this locally and have gotten it to work against a v1 app. Since Amplify is marked as stable and included in aws-cdk-lib, I think we should actually merge this as a new experimental module so users know there may be changes to the API and/or behavior of the custom resource if needed.

To do this we will have to create a new package in packages/@aws-cdk that has stability experimental. This will automatically release as a separate package with -alpha appended to the name. I'm asking around for guidance on the best way to do this, IE what to name this module etc. As far as I can tell, it would be fairly easy to decouple this from the existing App construct and instead do something like new AmplifyAssetsDeploy(this, 'scope', myAmplifyApp) to create the custom resource.

What do you think about that?

Happy for it to be marked experimental. The change was originally decoupled as AmplifyAssetDeployment; from the suggestions above I made it part of the API however.

@MrArnoldPalmer
Copy link
Contributor

@samkio ahh yes I see. I think we should revert back to that structure and extract this into a separate module, perhaps @aws-cdk/amplify-assets, as that kinda follows some other naming we have, with stability: experimental. Once stabilized I do think adding as a method on the existing Branch class is ideal. @jogold cool with that?

I'm able to help with this if you run into issues or are just working on other stuff.

@jogold
Copy link
Contributor

jogold commented Dec 13, 2021

But @aws-cdk/aws-amplify is still experimental...

"stability": "experimental",
"maturity": "experimental",

and already published separately https://www.npmjs.com/package/@aws-cdk/aws-amplify-alpha

const asset = new assets.Asset(this, "SampleAsset", {});
const amplifyApp = new amplify.App(this, 'MyApp', {});
const branch = amplifyApp.addBranch("dev");
branch.addAssetDeployment(asset);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I suggested this addAssetDeployment() but thinking more about this, can we add more than one asset deployment to a branch? I don't think so. So maybe it should be moved to a construction prop in Branch/option in addBranch()?

Copy link
Contributor Author

@samkio samkio Dec 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good; amended.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to update the README for the latest change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@MrArnoldPalmer
Copy link
Contributor

oh wow, completely disregard what I said, I was looking at the wrong package apparently? I'm not exactly sure where I got this idea from.

MrArnoldPalmer
MrArnoldPalmer previously approved these changes Dec 14, 2021
@MrArnoldPalmer MrArnoldPalmer dismissed their stale review December 14, 2021 16:29

Discussing NodeJSFunction usage

@mergify
Copy link
Contributor

mergify bot commented Dec 14, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: ebb20bd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 499ba85 into aws:master Dec 14, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 14, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
This change adds a custom resource that allows users
to publish S3 assets to AWS Amplify.

fixes aws#16208


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-amplify Related to AWS Amplify effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-cdk/aws-amplify): Add a sourceCodeProvider for S3 or Zipped Asset
7 participants