AWS Lambda allows you to create functions on your local computer, including 3rd party libraries, then upload all of that code using the AWS command line. When you use the AWS command-line, you will need to package the files as a .Zip.

Below are the two most common ways of archiving files using the command line. Zip is common for Windows users but Linux tends to use Tarball.

For AWS Lambda, you will generally use Zip, but I include both for completeness.



This example shows how to compress files into a zip folder recursively – and exclude items such as package.json, npm.log, and file.

zip -r my_zip_package * -x .* -x "package.json" -x "*.log" -x *.md
  • zip -r my_zip_package * means to create and recursively include everything in this folder.
  • -x "package.json" means to exclude any files with this name.
  • .* means to exclude any hidden files such as .DS_Store.
  • -x *.log means to exclude anything with a .log extension.
  • -x *.md means exclude anything with a .md extension such as


Example 1

Unzip a .zip file.

unzip -d /path/to/directory


Tar is short for Tape Archive and is unique in that you can pick a compression. For example, you can pick between gzip, bzip2 or xz.

You can always learn more by reading the manual.

man tar


Example 1

Create a tarball using gzip compression.

tar -cpvzf my_tar_archive.tar.gz /path/to/directory
  • -c Create an archive.
  • -v means "verbose mode" and will list every file as it's being processed.
  • -z Compress the archive using gzip.
  • -p means to preserve permissions (extract all protection information)
  • -f Allows you to specify the filename of the archive.

Back up a directory and exclude any hidden files such as .DS_Store.

Example 2

This example excludes files with a specific extension or characteristic.

tar -cpvjf my_tar_archive.tar.gz /path/to/directory --exclude=*.psd --exclude=".*"
  • -j Use bzip2 compression.
  • --exclude=*.psd Exclude any Photoshop files.
  • --exclude=".*" Exclude any hidden files.


Example 1

Extract an archive.

tar -xzvf my_tar_archive.tar.gz -C /path/to/directory
  • -x Extract files.
  • -v means "verbose mode" and list every file as its being processed.
  • -f Allows you to specify the filename of the archive.
  • -C Extract the files to a specific directory.

Next Steps

Now that we've gone over the basic commands, our next step should be to create scripts that can help us automate the process of packaging and publishing our code to Lambda.

My article on Managing AWS Commands using JakeJS will show you how I package all of my Lambda functions for deployment into a single script.