Home - nolim1t/opencv-aws-lambda GitHub Wiki

Welcome to the opencv-aws-lambda wiki!

Setting up

Set up an Amazon Linux EC2 instance

  • Go into the EC2 control panel and set up an Amazon Linux EC2 instance
  • Log on using ec2-user and use the keypair that you have generated

Type the following at the command line

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash

Then exit out

And then log in and do

nvm ls-remote

and then install the 0.10.33 (The version must be exact). For example

nvm install v0.10.33

then do

mkdir lambdaTestFunction
cd lambdaTestFunction
npm install --prefix=~/lambdaTestFunction aws-sdk
echo 'var AWS = require("aws-sdk");console.log(AWS.EC2.apiVersions)'> test.js
node test.js

If there is no errors and you see a list, everythings good so far.

Now install OpenCV

sudo yum update
sudo yum install gcc44 gcc-c++ libgcc44 cmake –y
wget https://github.com/Itseez/opencv/archive/2.4.9.zip
mkdir opencv_install
mkdir opencv_example
cd opencv_install
unzip ~/2.4.9.zip
make && make install
cd ~/lambdaTestFunction
npm init # then fill out stuff
PKG_CONFIG_PATH=~/opencv/lib/pkgconfig/ npm install opencv --save

Deploy the lambda

  • Assuming role arn:aws:iam::518627074072:role/lambda_and_s3 has been created
  • Deploy to a function called lambdaTestFunction
cd ~/lambdaTestFunction
rm ~/lambdaTestFunction.zip
zip -r ~/lambdaTestFunction.zip *
aws lambda create-function --function-name lambdaTestFunction \
--runtime nodejs \
--handler index.handler \
--description "Test lambda function" \
--role arn:aws:iam::518627074072:role/lambda_and_s3 \
--zip-file fileb://../lambdaTestFunction.zip

For updates

cd ~/lambdaTestFunction
rm ~/lambdaTestFunction.zip
zip -r ~/lambdaTestFunction.zip *
aws lambda update-function-code --function-name lambdaTestFunction --zip-file fileb://../lambdaTestFunction.zip