Skip to content

A set of Python Pillow Lambda functions to cover day-to-day use cases

License

Notifications You must be signed in to change notification settings

jDmacD/aws-lambda-pillow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-lambda-pillow

Description

A toolkit of Lambda functions, implemented using Pillow, to cover day-to-day use cases:

  • Resizing
  • Format Conversion
  • Watermarking
  • Composositing
  • Meta-Data Manipulation

The Lambda functions are designed to integrate with S3, API Gateway and will eventually include a Cloudformation template.

Image Return Modes

At the moment Lambda, and API Gateway, have significant restrictions on what can be returned. As such the are several options:

  • 64-bit encoded string (up to 6mb)
  • Signed S3 URL (unlimited size)
  • JSON: {"Bucket": "<YOUR IMAGE BUCKET>", "Key":"<YOUR IMAGE KEY>"}

Supported Formats

  • jpeg
  • tiff
  • png
  • webp
  • bmp
  • gif

Setup

a config.json file is required in the root of the project with the following attributes

{
  "accessKeyId": "< REQUIRED: YOUR KEY ID >",
  "secretAccessKey": "<  REQUIRED: YOUR ACCESS KEY >",
  "region": "< REQUIRED: YOUR AWS REGION >",
  "codeBucket":"< REQUIRED: YOUR CODE BUCKET >",
  "imageBucket":"< REQUIRED: YOUR IMAGE BUCKET >",
  "KeyName": "< OPTIONAL: YOUR EC2 PEM NAME >",
  "SecurityGroupIds": [
    "< OPTIONAL: YOUR EC2 SECURITY GROUP ID >"
  ]
}

Virtualenv Bundle

To enable support for the broadest possible spectrum of image formats a virtualenv deployment package is required. To ensure compability, the virtualenv bundle (env.zip) has been built using the same Linux AMI that Lambda utilises.

The virtualenv bundle (env.zip) in this project includes the following Python packages:

  • pillow
  • simplejson
  • eventlet
  • requests

Warning Boto3 is not included by default, as it already installed on Lambda.

If you want to enable Boto3 (to test locally for example), or add other pip installable packages and dependencies:

  1. Uncomment pip install --verbose --use-wheel boto3 in userData.sh.
  2. Execute grunt make-env. This will perform the following actions:
    • Launch an ec2
    • Perform yum installs
    • Create a virutalenv
    • Perform pip installs
    • Zip lib and lib64 to env.zip
    • Copy env.zip to the codeBucket defined in the config.json
  3. This operation will take about 5 minutes.
  4. Execute grunt get-env. This will download the new env.zip, overwriting the original.

About

A set of Python Pillow Lambda functions to cover day-to-day use cases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published