Last Updated: February 25, 2016
·
3.306K
· rra3

Zipfile quirks when deploying a Node.js app to AWS Elastic Beanstalk

Yesterday my team was just trying to get a simple Node.js prototype running on Elastic Beanstalk. We ran into some small problems which aren't exactly spelled out in the documentation. On the Elastic Beanstalk dashboard, there is a form upload where you can upload a zipfile of your app:Picture

I tried simply downloading a zip file from my github repo, and uploading it to AWS. I waited for the app to deploy, and it failed. Checking the snapshot logs, (which you can do directly from the app dashboard in AWS), I noticed that it was looking for package.json in /var/app/current/package.json.

I ssh'd into the server, and discovered that the zip file was being unzipped into /var/app/current, but also creating an extra directory level there, e.g. /var/app/current/githubrepodir/.

The fix was to simply create a zip file that would unzip directly into the target directory without creating an extra folder level. I believe the Elastic Beanstalk deploy process might understand nested directories with rails apps, but the same doesn't seem to be the case with Node apps. In any case, it does expect to find package.json directly under the "current" directory - I suppose you could then configure package.json with directives to find the js files themselves in a directory structure from there with an arbitrary nesting structure.

Also, check your package.json with a lint script. I was missing the version field in mine, which invalidated it. You can easily find a relevant web app, such as this one.