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

4.50.0 error: Cannot read property 'length' of undefined #7190

Closed
4 tasks done
hisham opened this issue Apr 27, 2021 · 20 comments · Fixed by #7192
Closed
4 tasks done

4.50.0 error: Cannot read property 'length' of undefined #7190

hisham opened this issue Apr 27, 2021 · 20 comments · Fixed by #7192
Assignees
Labels
api-rest Issues tied to REST APIs bug Something isn't working referenced-in-release Issues referenced in a published release changelog

Comments

@hisham
Copy link
Contributor

hisham commented Apr 27, 2021

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

AWS Amplify Build

If applicable, what version of Node.js are you using?

Not sure - whatever AWS Amplify uses

Amplify CLI Version

4.50.0

What operating system are you using?

Amazon Linux I assume

Amplify Categories

api

Amplify Commands

push

Describe the bug

Just did a very simple push that triggered CI in AWS Amplify. Got the following error. This build was working fine before 4.50.0. Our amplify build is set to push with latest amplify always.

2021-04-27T17:24:54.129Z [WARNING]: ✖ An error occurred when pushing the resources to the cloud
2021-04-27T17:24:54.130Z [WARNING]: ✖ There was an error initializing your environment.
2021-04-27T17:24:54.133Z [INFO]: �[0mTypeError: Cannot read property 'length' of undefined�[0m
                                 �[0m    at /usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:121:99�[0m
                                 �[0m    at Array.forEach (<anonymous>)�[0m
                                 �[0m    at ApiGatewayAuthStack.createPoliciesFromResources (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:120:13)�[0m
                                 �[0m    at /usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:94:16�[0m
                                 �[0m    at Array.forEach (<anonymous>)�[0m
                                 �[0m    at /usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:84:31�[0m
                                 �[0m    at Array.forEach (<anonymous>)�[0m
                                 �[0m    at new ApiGatewayAuthStack (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:62:23)�[0m
                                 �[0m    at createApiGatewayAuthResources (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:205:17)�[0m
                                 �[0m    at Object.consolidateApiGatewayPolicies (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:201:10)�[0m
                                 �[0m    at Object.createEnvLevelConstructs (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/env-level-constructs.ts:22:5)�[0m
                                 �[0m    at runMicrotasks (<anonymous>)�[0m
                                 �[0m    at processTicksAndRejections (internal/process/task_queues.js:93:5)�[0m
                                 �[0m    at Object.run (/usr/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/push-resources.ts:97:5)�[0m
2021-04-27T17:24:54.152Z [ERROR]: !!! Build failed
2021-04-27T17:24:54.152Z [ERROR]: !!! Non-Zero Exit Code detected

Expected behavior

Should just work

Reproduction steps

  1. I did a very simple frontend push and AWS Amplify started deploying backend and frontend. I made no backend changes. This deployment succeeded 2 hours ago before 4.50.0 was released.

GraphQL schema(s)

# Put schemas below this line

Log output

# Put your logs below this line


Additional information

I have not tested yet locally or with < 4.50.0. Will do now.

@hisham
Copy link
Contributor Author

hisham commented Apr 27, 2021

Setting AWS Amplify to use 4.49.0 resolved the issue and backend push went through fine.

Let me know if you need any additional info or want me to try to do a backend push on my local machine with 4.50.0. Until then I'll leave this in your hands :).

@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2021

If you could share the contents of amplify/backend/api/${YOUR_REST_API}/api-params.json (with any sensitive information redacted), that would be great.

@cjihrig cjihrig self-assigned this Apr 27, 2021
@hisham
Copy link
Contributor Author

hisham commented Apr 27, 2021

Sure I just emailed it to [email protected]

@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2021

Thank you for reporting this. We are working on a fix. In the mean time, if you run amplify api update to regenerate the api-params.json file, that should fix the issue on v4.50.0.

@jacobhobson
Copy link

@cjihrig, just a heads up, running an amplify api update did not fix the issue. I'll have to revert to 4.49.0 for the time being, but I'll take whatever workarounds you've got!

@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2021

@jacobhobson is your api-params.json file missing policyResourceName fields?

@jacobhobson
Copy link

@cjihrig, no, that field is not missing. Each path element object has the policyResourceName property.

@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2021

OK, and you are seeing the same error as the OP, right? If so, can you share your api-params.json file either here or via an email to [email protected].

@blairtaylor
Copy link

We are getting the same error. It is occurring on CLI 4.50.0.

Forcing the build CLI to 4.49.0 we were able to work around this issue.

Starting phase: build

Executing command: amplifyPush --simple

2021-04-27T20:55:48.200Z [INFO]: [0mAmplify AppID found: d2y376scxw2k21. Amplify App name is: xxxxx-staging-ci[0m
2021-04-27T20:55:48.248Z [INFO]: [0mBackend environment staging found in Amplify Console app: xxxxx-staging-ci[0m
2021-04-27T20:55:50.277Z [WARNING]: - Fetching updates to backend environment: staging from the cloud.
2021-04-27T20:55:52.022Z [WARNING]: :heavy_check_mark: Successfully pulled backend environment staging from the cloud.
2021-04-27T20:55:52.405Z [INFO]:
2021-04-27T20:55:54.472Z [INFO]: [33mNote: It is recommended to run this command from the root of your app directory[39m
2021-04-27T20:56:01.063Z [WARNING]: - Initializing your environment: staging
2021-04-27T20:56:25.654Z [WARNING]: :heavy_check_mark: Initialized provider successfully.
2021-04-27T20:56:26.261Z [WARNING]: :heavy_multiplication_x: An error occurred when pushing the resources to the cloud
2021-04-27T20:56:26.264Z [WARNING]: :heavy_multiplication_x: There was an error initializing your environment.
2021-04-27T20:56:26.267Z [INFO]: [0mTypeError: Cannot read property 'length' of undefined[0m
[0m at /root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:121:99[0m
[0m at Array.forEach ()[0m
[0m at ApiGatewayAuthStack.createPoliciesFromResources (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/src/utils/consolidate-apigw-policies.ts:120:13)[0m

@cjihrig
Copy link
Contributor

cjihrig commented Apr 27, 2021

@blairtaylor can you confirm if any of your REST API paths are missing a policyResourceName property in api-params.json. If so, please try running amplify api update and then verify the policyResourceNames again.

@gakinson
Copy link

+1 , we are experiencing the same issue

@sferencik
Copy link

sferencik commented Apr 28, 2021

I've emailed our api-params.json too. Good luck!

@wbroek
Copy link

wbroek commented Apr 28, 2021

Got the same error when running with amplify version 4.50.0: TypeError: Cannot read property 'length' of undefined

Then ran amplify api updates and did update path choice and choose the values that were already there. After that I saw it changes the file api-params.json ( "policyResourceName": "/..." was added) but also the file userapi-cloudformation-template.json was changed ( "authRoleName" and "unauthRoleName" where removed).

When I push this with amplify push I get the error:

UPDATE_FAILED               api                         AWS::CloudFormation::Stack Wed Apr 28 2021 16:41:38 GMT+0200 (Central European Summer Time) Parameters: [authRoleName, unauthRoleName] do not exist in the template

well, yes the where removed in userapi-cloudformation-template.json but why? (also the file APIGatewayAuthStack.json was generated)

@edwardfoyle edwardfoyle added api-rest Issues tied to REST APIs bug Something isn't working labels Apr 28, 2021
@cjihrig
Copy link
Contributor

cjihrig commented Apr 28, 2021

@wbroek thank you for your input. If your API's parameters.json file still references the authRoleName and/or unauthRoleName, you can remove them. The file will likely contain just an empty object {}. From there, you can try pushing again. There is a chance you will need to use the --force flag with amplify push. I've put together a patch in #7192, which should handle all of these steps automatically in the future.

@wbroek
Copy link

wbroek commented Apr 28, 2021

@cjihrig thanks that did the trick. Removed them in the parameters.json and pushed as you mentioned. Thanks again @cjihrig

@ondrej-hegedus
Copy link

Thank you for reporting this. We are working on a fix. In the mean time, if you run amplify api update to regenerate the api-params.json file, that should fix the issue on v4.50.0.

What to do when amplify api update doesn't generate the api-params.json?
I tried doing in in versions 4.50.0 and 4.49.0

attilah pushed a commit that referenced this issue Apr 29, 2021
* fix: ensure policy resource name when pushing REST APIs

It is possible that older REST APIs have never been updated to
include the policyResourceName field on paths. This commit
ensures that the field is present.

Refs: #7190

* fix: process CFN and parameters.json separately

When removing the auth and unauth roles from REST APIs, the
CFN template and the parameters.json file should be processed
separately in case they have gotten out of sync. Otherwise, the
generated root stack is likely to have errors.

* fix: ignore AdminQueries during REST API consolidation

This commit moves the check for AdminQueries from
consolidateApiGatewayPolicies() to loadApiWithPrivacyParams(),
as the latter is also called from push-resources.ts.

* fix: add AdminQueries to multiple REST API test

* fix: don't throw on malformed path

Co-authored-by: Colin Ihrig <[email protected]>
@evertson90
Copy link

Had the same issue. Using 4.49.0 fixed the problem.

@Stvad
Copy link

Stvad commented May 2, 2021

I see this is closed, but I'm still experiencing the issue in the backend build (it seems LATEST still resolves to 4.50.0 there, were the changes released?)

@siegerts
Copy link
Contributor

siegerts commented May 4, 2021

👋 Hi, this issue was referenced in the v4.50.2 release!

Check out the release notes here https://github.com/aws-amplify/amplify-cli/releases/tag/v4.50.2.

@siegerts siegerts added the referenced-in-release Issues referenced in a published release changelog label May 4, 2021
@github-actions
Copy link

github-actions bot commented Jun 3, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-rest Issues tied to REST APIs bug Something isn't working referenced-in-release Issues referenced in a published release changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.