|
1 |
| -# aws-lambda-python-opencv |
2 |
| -Simple script for building an AWS Lambda deployement package including OpenCV |
| 1 | +# Python OpenCV module for AWS Lambda |
| 2 | + |
| 3 | +This is a simple script that build a deployement package including OpenCV compatible with the AWS Lambda Python runtime. The dynamic library is compiled with all extended instruction sets supported by Lambda CPU and binaries are stripped to save space. You simply need to add your code inside *lambda_funcion.py* and possibly your haar cascades files or additional Python modules. You can download directly a [pre-built archive](https://github.com/Plastic-1/aws-lambda-python-opencv/archive/prebuilt.zip). |
| 4 | + |
| 5 | +- Build duration: ~20 min on T2.micro / ~15 min on C4.2xlarge |
| 6 | +- Package size without haar cascades included: 26MB |
| 7 | +- OpenCV 3.1 by default but may works with newer |
| 8 | + |
| 9 | +**Need to be built on an Amazon Linux instance.** |
| 10 | + |
| 11 | +## Module building |
| 12 | +### Option 1: with an existing instance |
| 13 | + - Download the repo `wget https://github.com/Plastic-1/aws-lambda-python-opencv/archive/master.zip` |
| 14 | + - Unzip the archive `unzip master.zip` |
| 15 | + - Launch the script `cd aws-lambda-python-opencv-master && ./build.sh` |
| 16 | + |
| 17 | +### Option 2: without an existing instance |
| 18 | +On the EC2 console, launch a new instance with: |
| 19 | +- Amazon Linux AMI |
| 20 | +- Role with S3 write permission |
| 21 | +- Shutdown behavior: *Terminate* |
| 22 | +- Paste the script below in the user data text field |
| 23 | +```sh |
| 24 | +#!/bin/bash |
| 25 | + |
| 26 | +yum update -y |
| 27 | +yum install -y git cmake gcc-c++ gcc python-devel chrpath |
| 28 | + |
| 29 | +cd /tmp |
| 30 | +wget https://github.com/Plastic-1/aws-lambda-python-opencv/archive/master.zip |
| 31 | +unzip master.zip |
| 32 | +chmod 777 aws-lambda-python-opencv-master |
| 33 | +cd aws-lambda-python-opencv-master |
| 34 | +su -c './build.sh' ec2-user |
| 35 | + |
| 36 | +aws s3 cp lambda-package.zip s3://<my-target-bucket> |
| 37 | +shutdown -h now |
| 38 | +``` |
| 39 | +- Replace *<my-target-bucket>* by a bucket or your choice |
| 40 | +- Less than 30 min later the instance will be terminated and the archive will be available on your bucket |
0 commit comments