2

I am developing AWS Lambda (NET6). During the Github action execution (build, zip, upload) in a CloudFormation yml file, I have received the error:

Run zip -jr customerlambda-356e9e4b8869b2cf7f483d739aa5a8aa34e0fc13.zip -i ./bin/Release/net6.0/publish/*

zip error: Invalid command arguments (nothing to select from)
Error: Process completed with exit code 16.

It is in Ubuntu-latest environment.

What is incorrect here?

1
  • Which distro and version of Linux are you using?
    – user68186
    Jul 17 at 15:10

1 Answer 1

6

You seem to want:

zip -jr customerlambda-356e9e4b8869b2cf7f483d739aa5a8aa34e0fc13.zip \
./bin/Release/net6.0/publish/

i.e. without -i ... With the -i(include) option, you still haven't specified the path to the source file(s)/directory(ies) and hence the error:

zip error: Invalid command arguments (nothing to select from)

Notice one:

./bin/Release/net6.0/publish/ seems to be the relative path to where your source files/directories are, but adding -i before it will turn it into an argument to the -i option instead of an argument to the zip command itself ... Therefore as far as the zip command is concerned, there is no source file/directory argument ... and, you don't need to include that directory's contents with -i as the -r option will recurse through the contents of that directory so you dont need to use *(which you better escape with a backslash \* when used) either ... So simply remove -i and *.

Notice two:

The -j option will result in zip storing just the name(s) of a saved file(s) and not storing directory names(i.e. paths relative to the current directory) ... That might cause a problem when used with the -r option as duplicate identical filenames might exist in sub-directories that will be recursed by the option -r set which will result in zip receiving repeated filenames to store in the archive which it cannot do and will result in an error like:

zip error: Invalid command arguments (cannot repeat names in zip file)

So, you might not want to use -j in that case.

Notice three:

While relative paths in the form of ./subdir/subdir2/ and archive.zip will work and be parsed relative to the current working directory, it might be a good idea in scriptfiles to use the full real path for both the output archive and the source directory(ies)/file(s) like for example if your source directory is:

/home/runner/work/PM2AWSCustomers/PM2AWSCustomers/bin/Release/net6.0/publish/

and you want the resulting archive file named to be customerlambda.zip and saved in:

/home/runner/work/PM2AWSCustomers/

then use the zip command like so:

zip -r /home/runner/work/PM2AWSCustomers/customerlambda.zip \
/home/runner/work/PM2AWSCustomers/PM2AWSCustomers/bin/Release/net6.0/publish/

the backslash \ is used to escape the newline used for redability purposes in this post and will make the shell read the command as one liner ignoring the escaped newline.

8
  • These are source files ./bin/Release/net6.0/publish/
    – ZedZip
    Jul 17 at 17:26
  • @ZedZip That is clear to me, but adding -i before it will turn it into an argument to the -i option instead of an argument to the zip command itself ... Therefore as far as the zip command is concerned, there is no source file/directory argument ... and, you don't need to include that directory's contents with -i as the -r option will recurse through the contents of that directory so you dont need to use *(which you better escape with a backslash when used) either ... So simply remove -i and *.
    – Raffa
    Jul 17 at 17:51
  • I have added pwd and ls command to understand what is the current directory for zip
    – ZedZip
    Jul 18 at 6:24
  • It is /home/runner/work/PM2AWSCustomers/PM2AWSCustomers PM2AWSCustomers <----folder PM2AWSCustomers.sln README.md aws I.e. I need to zip files in the folder PM2AWSCustomers/bin/Release/net6.0/publish what zip command should be in this case?
    – ZedZip
    Jul 18 at 6:27
  • @ZedZip I updated the answer for that ... I hope it's clear now.
    – Raffa
    Jul 18 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .