aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Deployment fails when creating and setting permissions on new table in same commit #7372

Closed yiweixia closed 3 years ago

yiweixia commented 3 years ago

Before opening, please confirm:

JavaScript Framework

Not applicable

Amplify APIs

GraphQL API

Amplify Categories

function

Environment information

``` System: OS: macOS 11.2.3 CPU: (8) x64 Apple M1 Memory: 23.94 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 15.12.0 - /usr/local/bin/node npm: 7.6.3 - /usr/local/bin/npm Browsers: Chrome: 90.0.4430.212 Firefox: 88.0.1 Safari: 14.0.3 npmPackages: @babel/cli: ^7.10.5 => 7.12.10 @babel/core: ^7.10.5 => 7.12.10 (7.9.0) @babel/plugin-proposal-class-properties: ^7.10.4 => 7.12.1 (7.8.3) @babel/preset-env: ^7.10.4 => 7.12.11 (7.9.0) @emotion/react: ^11.1.5 => 11.1.5 @emotion/styled: ^11.1.5 => 11.1.5 @fortawesome/fontawesome-free: ^5.13.0 => 5.15.1 @fortawesome/fontawesome-svg-core: ^1.2.28 => 1.2.32 @fortawesome/free-solid-svg-icons: ^5.13.0 => 5.15.1 @fortawesome/react-fontawesome: ^0.1.9 => 0.1.13 @material-ui/core: ^5.0.0-alpha.25 => 5.0.0-alpha.27 @material-ui/icons: ^5.0.0-alpha.24 => 5.0.0-alpha.27 @sentry/cli: ^1.63.1 => 1.61.0 @sentry/react: ^6.3.6 => 6.3.6 @sentry/rrweb: ^0.2.0 => 0.2.0 @sentry/tracing: ^6.3.6 => 6.3.6 @sentry/webpack-plugin: ^1.14.1 => 1.14.0 @testing-library/jest-dom: ^4.2.4 => 4.2.4 @testing-library/react: ^9.5.0 => 9.5.0 @testing-library/user-event: ^7.2.1 => 7.2.1 aws-amplify: ^3.3.4 => 3.3.13 body-parser: ^1.19.0 => 1.19.0 brace: ^0.11.1 => 0.11.1 classnames: ^2.2.6 => 2.2.6 copy-to-clipboard: ^3.3.1 => 3.3.1 cypress: ^5.4.0 => 5.6.0 example: undefined () formik: ^2.1.4 => 2.2.6 foundation-sites: ^6.6.1 => 6.6.3 husky: ^4.2.5 => 4.3.6 immutable: ^4.0.0-rc.12 => 4.0.0-rc.12 jsoneditor: ^9.0.0 => 9.1.5 jsoneditor-react: ^3.0.0 => 3.1.0 libphonenumber-js: ^1.9.11 => 1.9.13 libphonenumber-js-core: 1.0.0 libphonenumber-js-max: 1.0.0 libphonenumber-js-min: 1.0.0 libphonenumber-js-mobile: 1.0.0 lint-staged: ^10.2.11 => 10.5.3 lodash: ^4.17.21 => 4.17.20 mime-types: ^2.1.27 => 2.1.27 (2.1.11) mochawesome-report-generator: ^5.1.0 => 5.1.0 node-sass: ^4.13.1 => 4.14.1 prettier: ^1.19.1 => 2.2.1 prettier-airbnb-config: ^1.0.0 => 1.0.0 react: ^16.13.1 => 16.14.0 (16.13.1) react-alice-carousel: ^2.4.0 => 2.4.0 react-countdown-circle-timer: ^1.2.1 => 1.2.1 react-datepicker: ^2.15.0 => 2.16.0 react-device-detect: ^1.17.0 => 1.17.0 react-dom: ^16.13.1 => 16.14.0 react-ga: ^3.0.0 => 3.3.0 react-modal: ^3.11.2 => 3.12.1 react-phone-input-2: ^2.13.9 => 2.13.9 react-places-autocomplete: ^7.2.1 => 7.3.0 react-responsive-carousel: ^3.2.12 => 3.2.13 react-router: ^5.1.2 => 5.2.0 react-router-config: ^5.1.1 => 5.1.1 react-router-dom: ^5.1.2 => 5.2.0 react-scripts: 3.4.1 => 3.4.1 react-select: ^3.1.0 => 3.1.1 react-toastify: ^5.5.0 => 5.5.0 react_advanced_demo: 0.1.0 react_demo: 0.1.0 rrweb: ^0.9.14 => 0.9.14 source-map-explorer: ^2.4.2 => 2.5.1 uuid: ^8.1.0 => 8.3.2 (3.4.0, 3.3.2) yup: ^0.28.3 => 0.28.5 npmGlobalPackages: eslint: 7.25.0 lambda-local: 1.7.4 n: 7.0.1 node-prune: 1.0.2 npm: 7.6.3 webpack-cli: 4.5.0 webpack: 5.26.3 ```

Describe the bug

If I define a new @model in my schema.graphql, then try to give one of my functions access to it through the amplify CLI using

amplify function update -> select function -> resource access permissions -> storage -> choose table,

then push, the push fails with No export named qifwdw4eyfcabcgphqnnygcele:GetAtt:ExpendedBudgetTable:Name found

Expected behavior

The deployment should succeed, with the API changes being deployed first, and the resource permissions afterwards.

Reproduction steps

  1. Add a new table using the @model directive in schema.graphql
  2. amplify push
  3. Update a function to reference that new table using amplify function update -> select function -> resource access permissions -> storage -> choose table, e.g. MyTable: @model(appsync) -> give it permissions, etc.
  4. Commit code in one commit.
  5. Try deploying code to a different env

Code Snippet

N/A

Log output

``` UPDATE_FAILED functioncreateCardForUserCampaign AWS::CloudFormation::Stack Mon May 17 2021 23:21:49 GMT+0000 (Coordinated Universal Time) Embedded stack arn:aws:cloudformation:us-east-2:272407951964:stack/amplify-wesponsored-web-production-20723-functioncreateCardForUserCampaign-1BWFDKU94KSEO/b872d820-af9a-11ea-9960-023006f8d510 was not successfully updated. Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: No export named qifwdw4eyfcabcgphqnnygcele:GetAtt:ExpendedBudgetTable:Name found```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

chrisbonifacio commented 3 years ago

@josefaidt transferred as this sounds like more of a cli issue than a js one.

ammarkarachi commented 3 years ago

@yiweixia This is a bug I can verify that for now you could push the api first by invoking amplify push api and then do an amplify push. The lambda function gets deployed first and looks for the table while it's not deployed yet.

ngnathan commented 3 years ago

Thanks @ammarkarachi, I had the same issue.

I still had to remove the function before running amplify push api, which worked, and then re-added the function.

When I ran amplify push api it still tried to update the function (which fails), perhaps because the function still has a dependency on the API? I'm not really sure.

ammarkarachi commented 3 years ago

@ngnathan I believe we are missing a depends on when the deployment happens in the same call. As another workaround you could remove the permission and add the permissions back. I know this is kind of an inconvenience but we should have a fix out soon

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.