amazon-archives/awsmobile-cli

awsmobile cloud-api enable error: unexpected token

tbehunin opened this issue · 2 comments

I hit a run-time error when trying to enable cloud-api (on awsmobile-cli@1.1.5):

$ awsmobile cloud-api enable

cloud-api onFeatureTurnOn error:
/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/lib/feature-operations/scripts/cloud-api-ops.js:355
        ...path,
        ^^^

SyntaxError: Unexpected token ...
    at createScript (vm.js:74:10)
    at Object.runInThisContext (vm.js:116:10)
    at Module._compile (module.js:533:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.onFeatureTurnOn (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/lib/backend-operations/ops-cloud-api.js:83:35)
enabled: cloud-api
backend awsmobile project enabled features:
analytics, cloud-api, hosting, user-signin

As you can see at the end of the output, it seems to indicate that cloud-api is enabled. However, that run-time error makes me feel otherwise. The only thing that changed in my repo was mobile-hub-project.yaml:
image

If I attempt to run awsmobile push, I get the following output:

$ awsmobile push

checking the backend contents
Warning: no codebase found for lambda function: sampleCloudApi/items: sampleLambda
Warning: no codebase found for lambda function: sampleCloudApi/items/{proxy+}: sampleLambda
   generating backend project content
   done
backend build artifacts are saved at:
/Users/toddbehunin/code/polzee-mobile/awsmobilejs/.awsmobile/backend-build

preparing for backend project update: polzee-mobile-2018-08-06-22-05-56
done

updating backend project: polzee-mobile-2018-08-06-22-05-56
Failed to update project polzee-mobile-2018-08-06-22-05-56
{ BadRequestException: Unable to find build artifact uploads/sampleLambda.zip in S3 bucket polzeemobile-deployments-mobilehub-2089413617 for API function sampleLambda
    at Object.extractError (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/protocol/json.js:48:27)
    at Request.extractError (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/protocol/rest_json.js:52:8)
    at Request.callListeners (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/Users/toddbehunin/.nvm/versions/node/v8.1.3/lib/node_modules/awsmobile-cli/node_modules/aws-sdk/lib/request.js:685:12)
  message: 'Unable to find build artifact uploads/sampleLambda.zip in S3 bucket polzeemobile-deployments-mobilehub-2089413617 for API function sampleLambda',
  code: 'BadRequestException',
  time: 2018-08-10T05:20:29.555Z,
  requestId: '931f57ab-6910-4b5c-843c-f31b3c40fe29',
  statusCode: 400,
  retryable: false,
  retryDelay: 69.25884689253434 }

Help!

Seems spread operator (...) was added since node 8.2.1
Try upgrading your node version to solve this.

(I usually install node6.10 and node8.10 in my development environment, same as Lambda node version)

@ronald8192 ah yes that’s precisely the issue. I updated node to 8.11.3, tried again, and it worked just fine. Thanks!