Skip to content

Commit ed056b5

Browse files
authored
feat(lambda): influxdb-client-python in AWS Lambda Layer zip (#160)
1 parent 25626c7 commit ed056b5

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.circleci/config.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ jobs:
108108
command: |
109109
pip install pydocstyle --user
110110
pydocstyle --count influxdb_client
111+
check-aws-lambda-layer:
112+
docker:
113+
- image: docker:19
114+
steps:
115+
- checkout
116+
- setup_remote_docker
117+
- run:
118+
name: Create Archive to upload as a custom Lambda Layer
119+
command: |
120+
cd docker/aws_lambda_layer
121+
docker build -t lambdalayer:latest .
122+
docker create --name lambdalayer lambdalayer:latest
123+
docker cp lambdalayer:/install/python.zip .
111124
112125
workflows:
113126
version: 2
@@ -143,4 +156,5 @@ workflows:
143156
only:
144157
- master
145158
jobs:
146-
- tests-python
159+
- tests-python
160+
- check-aws-lambda-layer

docker/aws_lambda_layer/Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM amazonlinux:2
2+
RUN mkdir /install
3+
WORKDIR /install
4+
RUN yum install -y amazon-linux-extras
5+
RUN amazon-linux-extras enable python3.8
6+
RUN yum install -y python38 python38-devel python3-pip zip gcc
7+
RUN python3.8 -m pip install --upgrade pip && \
8+
python3.8 -m pip install virtualenv
9+
RUN python3.8 -m venv lambda
10+
RUN source lambda/bin/activate
11+
# Python dependencies to be included in output zip file:
12+
RUN python3.8 -m pip install influxdb-client[ciso] -t /install/python
13+
# Create zip file
14+
RUN zip -r /install/python.zip python/
15+
VOLUME ["/install"]

docker/aws_lambda_layer/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## AWS Lambda Layer Docker image
2+
Docker image which allows user to create a zip file with all Python dependencies for a custom AWS Lambda function (by default with influxdb-client). This should be within the limit of 10MB per single browser upload (~3,5MB with just the influxdb-client-python library). If the zip archive is uploaded to a custom Lambda Layer then user is able to keep using the Console IDE for editing main Lambda function.
3+
### Build image:
4+
`docker build -t lambdalayer:latest .`
5+
### Create container:
6+
`docker create --name lambdalayer lambdalayer:latest`
7+
### Copy zip from container:
8+
`docker cp lambdalayer:/install/python.zip .`
9+
### Upload zip to AWS Lambda
10+
Use AWS CLI or AWS Console to create and upload archive to a custom Lambda Layer. Then import those dependencies in lambda function as usual.
11+
```
12+
...
13+
from influxdb_client import InfluxDBClient, Point
14+
...
15+
```
16+
### Reference:
17+
https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-dependencies
18+
https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-using

0 commit comments

Comments
 (0)