This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Added Layer creation section #24
Open
meyer1994
wants to merge
1
commit into
RemotePixel:master
Choose a base branch
from
meyer1994:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,48 @@ You can find a more complex example in https://github.com/RemotePixel/remotepixe | |
|
||
|
||
## Create a Lambda layer | ||
`TODO` | ||
For this example, I will use a pyhton Lambda as the use case scenario. | ||
|
||
According to AWS [docs](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html), a Lambda layer must have the following format: | ||
|
||
``` | ||
package.zip | ||
├── bin # executables | ||
├── lib # libraries | ||
├── lib64 # libraries 64-bit | ||
├── python # python packages | ||
└── share # shared libraries | ||
``` | ||
|
||
### Creating the package | ||
|
||
To create a layer, we just need to package all the thinfs we need into a `package.zip` with the format described above. To do that, we can use a slightly modified version of the preivous script: | ||
|
||
```bash | ||
docker run --name lambda -itd remotepixel/amazonlinux-gdal:3.0.1 /bin/bash | ||
# This is just an example, installing gdal bindings for python | ||
docker exec -it lambda bash -c 'mkdir python' | ||
docker exec -it lambda bash -c 'pip install gdal==3.0.1 -no-binary :all: -t python -U' | ||
docker exec -it lambda bash -c 'zip -r9 /tmp/package.zip python' | ||
docker exec -it lambda bash -c 'zip -r9 --symlinks /tmp/package.zip lib/*.so*' | ||
docker exec -it lambda bash -c 'zip -r9 --symlinks /tmp/package.zip lib64/*.so*' | ||
docker exec -it lambda bash -c 'zip -r9 --symlinks /tmp/package.zip bin' | ||
docker exec -it lambda bash -c 'zip -r9 /tmp/package.zip share' | ||
docker cp lambda:/tmp/package.zip package.zip | ||
docker stop lambda | ||
docker rm lambda | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, see make rules and scripts in #22 |
||
|
||
The above script should result in a `package.zip` that can be uploaded as a Lambda layer. If you are using Chalice as the deployment tool, you do not need, per this example, to include `gdal` in the requirements file. It will be already available for use. But, you should have it installed locally, or Chalice won't deploy. | ||
|
||
### Environment variables | ||
|
||
You should, also, include some environment variables to your function. Mainly: | ||
|
||
```bash | ||
PROJ_LIB="/opt/share/proj" | ||
GDAL_DATA="/opt/share/gdal" | ||
``` | ||
|
||
## Package architecture and AWS Lambda config | ||
:warning: AWS Lambda will need `GDAL_DATA` to be set to `/var/task/share/gdal` to be able to work :warning: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work for py3.6 or py3.7 lambda layers, they need libs to be packaged into
python/lib/python${PY_VERSION}/site-packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you 100% sure about that? I am currently using a layer, created like I described, using python 3.7. According to AWS' docs, it appears that using only
python/
works.The following part is copied form the above link:
The
package.zip
that I generated has the following format, for python packages:And I can import the packages normally in python. Like so:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/shrug - didn't work for me but updates in my MR script are working OK and AFAICT the full path to the python packages in a layer becomes:
/opt/python/lib/python3.7/site-packages/**
/opt/python/{packages_directly_here}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably does become
/opt/python/lib/python3.7/site-packages/**
. I was only pointing out that the path, inside thepackage.zip
, can be/python/your_lib
. AWS probably does some post processing after unzipping the layer package.