|
1 | 1 | ## "Using AWS Lambda layers to inject lantency into AWS Lambda functions" |
2 | 2 |
|
| 3 | +## Building the zip package on a MAC (easy on Linux) |
| 4 | +1. If you upload the Mac version of ZIP files with PIP requirements installed with a MAC environment, you’ll see "invalid ELF header" logs when you try to test your Lambda function. |
| 5 | +* You need Linux versions of library files to be able to run in AWS Lambda environment. That's where Docker comes in handy. |
| 6 | +* With Docker you can very easily can run a Linux container locally on your Mac, install the Python libraries within the container so they are automatically in the right Linux format, and zip up the files ready to upload to AWS. |
| 7 | +* You’ll need Docker for Mac installed first. (https://www.docker.com/products/docker) |
3 | 8 |
|
| 9 | +2. Spin up an Ubuntu container which will have the lambda code you want to package |
| 10 | + * run the following command: |
| 11 | + |
| 12 | + ``` |
| 13 | + $ docker run -v <full path directory with your code>:/working -it --rm ubuntu |
| 14 | + ``` |
| 15 | + The -v flag makes your code directory available inside the container in a directory called "working". |
| 16 | + You should now be inside the container at a shell prompt. |
| 17 | + |
| 18 | +3. Install pip and zip. |
| 19 | + * run the following commands: |
| 20 | + ``` |
| 21 | + $ apt-get update |
| 22 | + $ apt-get install python-pip |
| 23 | + $ apt-get install zip |
| 24 | + ``` |
| 25 | + |
| 26 | +4. Install the python requirements. |
| 27 | + * run the following commands: |
| 28 | + ``` |
| 29 | + $ cd working |
| 30 | + $ pip install -r python/requirements.txt -t ./python/.vendor |
| 31 | + ``` |
| 32 | + |
| 33 | +5. Package your code. |
| 34 | + * run the following commands: |
| 35 | + ``` |
| 36 | + $ zip -r chaos_lib.zip ./python |
| 37 | + ``` |
| 38 | + |
| 39 | +Voila! Your package file chaos_lib.zip is ready to be used in Lambda Layer. |
0 commit comments