1

Trying to build a zip package for AWS Lambda that runs a node app. I'm using OSX zip to package the lambda bundle like this:

zip -dg -q -FS -R function.zip index.js "*.json" node_modules

However, for some reason, the resulting zip file excludes the files under src folder as highlighted in the screenshot. It includes "only 2" files from core subfolder which makes this thing very strange.

I'm not too familiar with zip and the man pages don't point out anything odd that I might be doing.

Any idea what I'm missing?

enter image description here

Here's the resulting zip file

enter image description here

  • @Jesse_b I uploaded the resulting zip file's structure. I didn't realize until now but core seems weirder (it doesn't have lint.js). – Mrchief Apr 26 at 18:19
  • Oh, so those args are acting like patterns instead of actual filenames? You might be on to something. – Mrchief Apr 26 at 18:21
  • Yep, that was it! This works zip -dg -q -FS -R function.zip \"*.js\" node_modules/* \"*.json\". It may not be the final thing I want but this points me in the right direction. Thanks! If you post it as an answer, I'll accept it. – Mrchief Apr 26 at 18:25
  • That *.json pattern should in any case be "*.json" or '*.json', without escaping the quotes. – Kusalananda Apr 26 at 18:33
  • @Kusalananda You're right. I copy/pasted my npm script from package.json which is "build": "rm -rf function.zip && zip -dg -q -FS -R function.zip \"*.js\" \"*.json\" ", - hence the need for escaping. – Mrchief Apr 26 at 18:35
2

In the zip man page for the -R option it states the following:

   -R
   --recurse-patterns
          Travel the directory structure recursively starting at the current directory; for example:

                 zip -R foo "*.c"

          In this case, all the files matching *.c in the tree starting at the current directory are stored into a zip archive named foo.zip.  Note that *.c  will
          match file.c, a/file.c and a/b/.c.  More than one pattern can be listed as separate arguments.  Note for PKZIP users: the equivalent command is

So it is searching the directory tree for index.js, \"*.json\" (honestly not sure how it's handling that pattern or what you are trying to accomplish with it), and node_modules. However you have not specified "*.js" or anything similar to include the other .js files.

  • 1
    Yeah, I read that option wrong. I basically want my js, json files, and anything under node_modules. – Mrchief Apr 26 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.