Skip to content

Commit 68a3b69

Browse files
committed
Initial development
1 parent 0c7c5c1 commit 68a3b69

File tree

8 files changed

+73
-3
lines changed

8 files changed

+73
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example/dist/

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM alpine:latest
22
LABEL maintainer="Kilna kilna@kilna.com"
33
RUN apk add --no-cache --update python py-pip zip &&\
4-
pip install python-lambda && \
5-
mkdir /workspace
4+
pip install python-lambda
5+
mkdir /workspace
66
WORKDIR /workspace
77
CMD /bin/sh -i

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# alpine-aws-python-lambda
2-
Lightweight docker image for running and packaging python-lambda code
2+
Lightweight docker image for running and packaging python-lambda code.
3+
4+
This is based on the super useful python-lambda library:
5+
6+
<https://github.com/nficano/python-lambda/>
7+
8+
# Usage
9+
10+
An example of a usable project can be found in the <example/> directory. This example lambda function
11+
takes a JSON input file like event.json and returns an ASCII-art version of the text.
12+
13+
```$ cd example/
14+
```
15+
16+
The Dockerfile in the example directory loads the current workspace into the image and installs
17+
dependencies from the requirements.txt file:
18+
19+
```FROM kilna/alpine-aws-python-lambda
20+
COPY . /workspace
21+
RUN pip install -r requirements.txt
22+
```
23+
24+
To build a docker image called 'example-lambda-image' with the lambda function in it, run:
25+
26+
```$ docker build --tag example-lambda-image .
27+
```
28+
29+
If you want to execute the lambda function against an event.json input file:
30+
31+
```$ docker run example-lambda-image lambda invoke
32+
_ _ _ _ _ _ _
33+
| || | ___ | | | | ___ __ __ __ ___ _ _ | | __| | | |
34+
| __ | / -_) | | | | / _ \ _ \ V V / / _ \ | '_| | | / _` | |_|
35+
|_||_| \___| |_| |_| \___/ ( ) \_/\_/ \___/ |_| |_| \__,_| (_)
36+
|/
37+
38+
```
39+
40+
If you would like to see if your lambda function builds properly, run:
41+
42+
```$ docker run example-lambda-image lambda build
43+
```
44+
45+
If you would like to get a ZIP file of the lambda function suitable for uploading to Amazon:
46+
47+
```$ docker run example-lambda-image sh -c 'rm -rf dist* && lambda build 2&>1 >/dev/null && tar -c dist/*.zip' | tar -x -v
48+
dist/2017-08-31-212523-example-lambda.zip
49+
```
50+
51+

example/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM kilna/alpine-aws-python-lambda
2+
COPY . /workspace
3+
RUN pip install -r requirements.txt

example/config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function_name: example-lambda
2+
handler: service.handler
3+
description: Returns an ASCII-art version of provided text
4+

example/event.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"text": "Hello, world!"
3+
}

example/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xart

example/service.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python
2+
3+
import subprocess
4+
import json
5+
6+
def handler(event, context):
7+
font=event.get('font', 'Small')
8+
text=event.get('text', '')
9+
return subprocess.check_output( ['xart', '-f', font, text ] )

0 commit comments

Comments
 (0)