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

Amplify publish fails (with custom config) #1065

Closed cliffordh closed 5 years ago

cliffordh commented 5 years ago

I'm getting an error running "amplify publish". My build scripts run properly and the build output directory is correct, but I get this error:

` DONE Build complete. The dist/checker directory is ready to be deployed. INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html

frontend build command exited with code 0 ✖ Error has occured during publish. 2019-03-19T01:28:53.129Z - error: uncaughtException: NotFound: null date=Mon Mar 18 2019 21:28:53 GMT-0400 (Eastern Daylight Time), pid=66356, uid=501, gid=20, cwd=/Users/cliff/Work/vue/checker, execPath=/usr/local/Cellar/node/11.11.0/bin/node, version=v11.11.0, argv=[/usr/local/Cellar/node/11.11.0/bin/node, /usr/local/bin/amplify, publish], rss=125063168, heapTotal=93114368, heapUsed=58202488, external=872056, loadavg=[2.21044921875, 1.83349609375, 1.7041015625], uptime=1170266, trace=[column=35, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/services/s3.js, function=Request.extractError, line=563, method=extractError, native=false, column=20, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js, function=Request.callListeners, line=106, method=callListeners, native=false, column=10, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js, function=Request.emit, line=78, method=emit, native=false, column=14, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js, function=Request.emit, line=683, method=emit, native=false, column=10, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js, function=Request.transition, line=22, method=transition, native=false, column=12, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/state_machine.js, function=AcceptorStateMachine.runTo, line=14, method=runTo, native=false, column=10, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/state_machine.js, function=null, line=26, method=null, native=false, column=9, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js, function=null, line=38, method=null, native=false, column=12, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js, function=null, line=685, method=null, native=false, column=18, file=/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js, function=Request.callListeners, line=116, method=callListeners, native=false], stack=[NotFound: null, at Request.extractError (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/services/s3.js:563:35), at Request.callListeners (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js:106:20), at Request.emit (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js:78:10), at Request.emit (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:683:14), at Request.transition (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:22:10), at AcceptorStateMachine.runTo (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/state_machine.js:14:12), at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/state_machine.js:26:10, at Request. (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:38:9), at Request. (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/request.js:685:12), at Request.callListeners (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-provider-awscloudformation/node_modules/aws-sdk/lib/sequential_executor.js:116:18)]`

I've modified my npm package.json file to include a couple of extra build steps that fill the "dist" directory with additional files. I've confirmed that the dist correct is "correct", but it seems to choke up the amplify publish command. Here is my package.json scripts section:

"scripts": { "serve": "vue-cli-service serve", "build": "npm run static && npm run vue", "vue": "vue-cli-service build", "static": "hugo", "lint": "vue-cli-service lint" },

The above scripts change runs "hugo" to generate a static site, then the vue build command executes which drops my SPA into a subdirectory of the static site.

yuth commented 5 years ago

@cliffordh amplify publish does 2 things.

  1. Run amplify push which pushes all the changes to your resource to the cloud
  2. Publish the changes

From the error it looks like amplify could not find the Cloudformation stack. Could you provide the answer the following questions so I can narrow down why the Cloud formation stack is missing

  1. Whats the version of amplify cli do you have installed? You can get the version by running amplify -v
  2. Could you run amplify ls inside your project and paste the response of the command so I can see what resources you have
  3. How did you init the environment? Did you run amplify init or was this an project that was intialized in a different machine?
cliffordh commented 5 years ago

@yuth I narrowed down the problem...

MBPCH:checker cliff$ amplify -v 0.1.36

Environment was initialized with amplify init

Problem described:

Part of my workflow is to copy additional resources to the project/dist directory. One of those files is a "hidden" file .DS_Store. The presence of this file in the directory crashes the upload. After I remove any .DS_Store file the upload proceeds normallly. The .DS_Store file is a Mac OS X metadata file which contains information about icon position, window position, labels, etc. It is not necessary for the app to operate.

Now, I've more generally tested this problem and I've been able to reproduce this crash with a specific combination of directories and a hidden file (it does not need to be named .DS_Store). Here is a directory listing of my dist directory:

MBPCH:dist cliff$ find . . ./checker ./checker/index.html ./checker/css ./checker/css/chunk-vendors.6acb9ff2.css ./checker/css/app.8374ce11.css ./checker/js ./checker/js/chunk-vendors.d2b87ba8.js ./checker/js/app.fd65974d.js ./checker/js/app.fd65974d.js.map ./checker/js/chunk-vendors.d2b87ba8.js.map ./WEB-INF ./WEB-INF/.hidden

For some reason, the subdirectory name WEB-INF when it also includes a hidden file (shown above as .hidden), causes the crash. If I rename the directory from WEB-INF to something else there is no crash, likewise, if I remove the .hidden file then there is no crash.

My destination hosting bucket is empty (I manually emptied it) and still get the crash.

Cliff

yuth commented 5 years ago

@cliffordh thanks for the detailed analysis. We could have list of default ignore files and add the list of common hidden files.

In the mean time till this feature is added, you could explicitly ignore files from getting published by running amplify hosting configure and choosing Publish when asked Specify the section to configure

amplify hosting configure
? hosting bucket name issue-1065-20190320122249-hostingbucket
? Specify the section to configure
 Website
  CloudFront
❯ Publish
  exit
UnleashedMind commented 5 years ago

I was not able to reproduce the .DS_Store related issue.

I was able to reproduce the WEB-INF related issue. If the WEB-INF folder is at the root level inside the distribution folder, no matter what is inside it, the upload will fail.

It turned out to be a known issue with the S3 API. https://github.com/aws/aws-sdk-java/issues/1295

That issue was closed with a statement: "Got a response from the S3 service team. This is a known bug and no fix is currently planned. The suggested workaround is to use path style addressing as mentioned above."

UnleashedMind commented 5 years ago

The workaround would be to put WEB-INF folder inside a root folder, such as dist/www/WEB-INF/ The upload will then work without any issue.

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.