blackboard / lambda-selenium

Use Selenium Webdriver and Chrome inside AWS Lambda
MIT License
229 stars 52 forks source link

Add symlinks option to travis zip commands. #19

Open tsu-denim opened 6 years ago

tsu-denim commented 6 years ago

If you don't properly zip things for Lambda, prepare to have a crazy ride debugging your problems. This should be the first thing to check when there are weird things happening. Not everything that runs correctly in the docker-lambda container will run the same in AWS Lambda. The treatment of file properties happen to be one of them.

tar preserves file information. zip typically does not, and wildly varies from implementation.

The runnable deployment package can only be delivered as a zip archive. Creating a zip file that works in Lambda is surprisingly tricky. Use the "zip" command with bash on OSX and Ubuntu (Its missing from some distros). The known working implementation is the 3.0 version "Info-Zip", which is FOSS. Check this using zip --version in bash. When you are ready to archive your function for deployment to Lambda, within a bash session cd into the root folder of your function, then zip the contents with a wildcard and store in the parent directory.

Best way to zip a function

cd myFunction && zip --symlinks -q -r ../function.zip *

Zip doesn't preserve symlinks unless the --symlinks option is used. Neglecting this will interfere with how node uses the binary dependencies in node_modules/.bin. If the symlinks are not preserved, there will be a lot of "No Such File in ../../.bin" type errors since the original link has been erased, so the pointer is not forwarded to what should be a corresponding node_module. There is a nod to this in the AWS Lambda documentation in one of the called out notes at http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-deployment-pkg.html.

Note To include all hidden files, use the following option: zip -r9 ~/CreateThumbnail.zip .