Skip to content

Lambda service for extracting camera trap images from email attachments

License

Notifications You must be signed in to change notification settings

tnc-ca-geo/animl-email-relay

Repository files navigation

animl-email-relay

Lambda service for extracting images from wireless camera trap emails

About

animl-email-relay is a lambda function that is triggered when an email is copied into an s3 bucket by AWS Simple Email Service. To set up email receiving on SES, follow the instructions here.

Currently, the handler supports emails coming from the following camera makers:

Setup

Prerequisits

The instructions below assume you have the following tools globally installed:

  • Serverless
  • Docker
  • aws-cli

Create "animl" AWS config profile

The name of the profile must be "animl", because that's what serverles.yml will be looking for. Good instructions here.

Note: AWS SES only supports email receiving in a few regions.

Make a project direcory and clone this repo

mkdir animl-email-relay
cd animl-email-relay
git clone https://github.com/tnc-ca-geo/animl-email-relay.git
cd animl-email-relay

Clone serverless-python-requirements plugin

This project runs in a Python Lambda environment, which means that all Python dependencies must be installed in the OS in which the will be ultimately executed. To accomplish this we use a Serverless plugin called serverless-python-requirements that, on serverless deploy, spins up a Docker container to mimic the AWS Lambda Linux OS, downloads any Python requirements defined in requirements.txt within the container, and packages them up to be added to our Lambda deployment package.

The plugin works well for installing Python packages, but we also need to include a Perl executable (exiftool) and its dependencies in the final deployment package, and the serverless-python-requirements plugin doesn't support some functionalty that we need to make that happen out of the box (see issue here). I created a fix and pull request to support this, but until the PR is accepted we have to clone the repo into our project manually from my github profile. So from within the project root directory, execute the following:

mkdir .serverless_plugins
cd .serverless_plugins
git clone --single-branch --branch recursive-docker-extra-files https://github.com/nathanielrindlaub/serverless-python-requirements.git
cd serverless-python-requirements
npm install

Adding new Python packages

Perform the following steps if you need to use new Python packages in the Lambda function.

Create venv and activate it

In the parent directory of this project (one directory above root), run the following:

virtualenv venv --python=python3
source venv/bin/activate

Add dependencies

# Example package installs
pip install requests
pip install PyExifTool

Freeze dependenceies in requirements.txt

pip freeze > requirements.txt

# Deactivate venv when you're done
deactivate

Deployment

From project root folder (where serverless.yml lives), run the following to deploy or update the stack:

# Deploy or update a development stack:
serverless deploy --stage dev

# Deploy or update a production stack:
serverless deploy --stage prod

Related repos

Animl is comprised of a number of microservices, most of which are managed in their own repositories.

Core services

Services necessary to run Animl:

Wireless camera services

Services related to ingesting and processing wireless camera trap data:

Misc. services

About

Lambda service for extracting camera trap images from email attachments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published