• Stars
    star
    119
  • Rank 297,158 (Top 6 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A build tool for creating optimized Python AWS Lambda layers

python-lambda-layer-builder

Creates an AWS Lambda Layers structure that is optimized for: Lambda Layer directory structure, compiled library compatibility, and minimal file size.

This repo was created to address these issues:

  • Many methods of creating Lambda zip files for Python functions don't work for Lambda Layers
    • This is due to the fact Lambda Layers require specific library paths within the zip, where regular Lambda zips don't
  • Compiled dependencies must be created in an environment that matches the Lambda runtime
  • Reduce size of the layer by removing unnecessary libraries and files

Note: This script requires Docker and uses a container to mimic the Lambda environment.

Features

  • Builds either a zip file or a raw directory strucutre (e.g. if you want to use frameworks like Serverless for packaging) containing Python dependencies and places the libraries into the proper directory structure for lambda layers
  • Ensures compiled libraries are compatible with Lambda environment by using the lambci/lambda Docker container that mimics the lambda runtime environment
  • Optimized the zip size by removing .pyc files and unnecessary libraries
  • Allows specifying lambda supported python versions: 2.7, 3.6, 3.7 and 3.8
  • Automatically searches for requirements.txt file in several locations:
    • same directory as script
    • parent directory or script (useful when used as submodule)
    • function sub-directory of the parent directory

Installation

This function can be cloned for standalone use, into a parent repo or added as a submodule.

Clone for standalone use or within a repo:

# If installing into an exisiting repo, navigate to repo dir
git clone --depth 1 https://github.com/tobilg/python-lambda-layer-builder _build_layer

Alternatively, add as a submodule:

cd {repo root}
git submodule add https://github.com/tobilg/python-lambda-layer-builder _build_layer
# Update submodule
git submodule update --init --recursive --remote

Usage

$ ./build.sh -h
AWS Lambda Layer Builder for Python Libraries

Usage: build.sh [-p PYTHON_VER] [-n NAME] [-f] [-r] [-h] [-v]
  -p PYTHON_VER : Python version to use: 2.7, 3.6, 3.7, 3.8 (default 3.7)
  -n NAME       : Name of the layer
  -f REQ_PATH	  : Path to requirements file
  -r            : Raw mode, don't zip layer contents
  -d            : Don't install Python dependencies
  -s            : Don't strip .so files
  -h            : Help
  -v            : Display build.sh version
  • Run the builder with the command ./build.sh
    • or _build_layer/build.sh if installed in sub-dir
  • It uses the first requirements.txt file found in these locations (in order):
    • Input on the command line using the -f switch
    • Same directory as script
    • Parent directory of script (useful when used as submodule)
    • Function sub-directory of the parent directory (useful when used as submodule)
  • Optionally specify Python Version
    • -p PYTHON_VER - specifies the Python version: 2.7, 3.6, 3.7, 3.8 (default 3.7)

Custom cleaning logic

You can edit the _clean.sh file if you want to add custom cleaning logic for the build of the Lambda layer. The above part of the file must stay intact:

#!/usr/bin/env bash
# Change to working directory
cd $1
# ----- DON'T CHANGE THE ABOVE -----

# Cleaning statements
# ----- CHANGE HERE -----
rm test.xt

The _make.sh script will then execute the commands after the Python packages have been installed.

Uninstall

If installed as submodule and need to remove

# Remove the submodule entry from .git/config
git submodule deinit -f $submodulepath
# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/$submodulepath
# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f $submodulepath
# remove entry in submodules file
git config -f .git/config --remove-section submodule.$submodulepath

More Repositories

1

facebook-events-by-location

[DEPRECATED] A Express.js-based webservice to get public Facebook events by location
JavaScript
332
star
2

lsh

Run interactive shell commands on AWS Lambda
JavaScript
141
star
3

facebook-events-by-location-core

[DEPRECATED] Search Facebook events by location and proximity.
JavaScript
139
star
4

aws-fullstack-website

Deploy your fullstack websites without all the hassle on AWS with CloudFront, S3, ACM, Route53, API Gateway and Lambda via Serverless.
JavaScript
137
star
5

serverless-aws-static-websites

Deploy your static websites without all the hassle on AWS with CloudFront, S3, ACM and Route53 via Serverless
JavaScript
128
star
6

api2html

A CLI tool to transform Swagger/OpenAPI/AsyncAPI docs to beautiful HTML pages via Shins/Widdershins.
JavaScript
105
star
7

mesos-framework

A wrapper around the Mesos HTTP APIs for Schedulers and Executors. Write your Mesos framework in pure JavaScript!
JavaScript
61
star
8

aws-edge-locations

List of AWS edge location code prefixes
JavaScript
44
star
9

marathon-slack

Integration for Marathon's Event Bus with Slack
JavaScript
42
star
10

netlify-functions-landingpage

A serverless-less landing page project on Netlify, including a Mailchimp mailing list signup via functions.
JavaScript
35
star
11

docker-zookeeper-webui

Docker image for using `zk-web` as ZooKeeper Web UI
Shell
32
star
12

duckdb-nodejs-layer

Packaging DuckDB for Lambda functions. Example application: https://github.com/tobilg/serverless-duckdb
Python
22
star
13

docker-mongodb-marathon

[DEPRECATED] Please use https://github.com/tobilg/dcos-commons/tree/mongodb-replicaset/frameworks/mongodb-replicaset
JavaScript
18
star
14

mesos-envoy-sds

An Envoy Service Discovery Service for Mesos
JavaScript
17
star
15

serverless-cubejs

Serverless Cube.js backend infrastructure on AWS
JavaScript
17
star
16

mesos-framework-boilerplate

A boilerplate for developing Mesos frameworks with JavaScript
JavaScript
16
star
17

docker-livy

A Docker image for Livy, the REST Spark Server
Shell
15
star
18

gitlab-ci-runner-marathon

A customized Docker image for running scalable GitLab CI runners on Marathon
Shell
15
star
19

aws-lambda-api-call-recorder

A recorder of AWS API calls for Lambda functions
JavaScript
14
star
20

serverless-duckdb

An example of how to run DuckDB on AWS Lambda & API Gateway.
JavaScript
13
star
21

docker-predictionio

Docker container for the latest prediction.io version with most recent dependencies
Shell
12
star
22

mesos-js-framework

[DEPRECATED] Use https://github.com/tobilg/mesos-framework instead
JavaScript
8
star
23

docker-mesos-dns

A lightweight Mesos DNS Docker image. Currently based on v0.5.2
Shell
7
star
24

serverless-parquet-repartitioner

Lambda function to serverlessly repartition parquet files in S3
JavaScript
7
star
25

cfn-cur-report-definition

A custom CloudFormation resource for Cost and Usage Report ReportDefinitions
JavaScript
7
star
26

mesosdns-resolver

A bash script to resolve Mesos DNS SRV records to actual host:port endpoints
Shell
7
star
27

tile38-lambda-layer

A AWS Lambda layer for Tile38
Shell
6
star
28

docker-kafka-marathon

[DEPRECATED] A Docker image of Apache Kafka to be run on a Mesos cluster via Marathon
Shell
6
star
29

marathon-event-bus-client

A Node.js package for listening to the Marathon Event Bus
JavaScript
6
star
30

ceph-admin-ops-client

A Node.js wrapper for Ceph Object Gateway's Admin Ops API
JavaScript
6
star
31

nodejs-lambda-layer-builder

Build custom AWS Lambda layers for Node
Shell
6
star
32

buffered-queue

A simple to use buffering queue (no dependencies) which flexibly buffers objects, strings, integers etc. until either a maximum size is reached, or an interval has come to an end.
JavaScript
6
star
33

mesos-operator-api-client

Node.js client for the Mesos Operator HTTP API events (see http://mesos.apache.org/documentation/latest/operator-http-api/)
JavaScript
6
star
34

docker-mini-webserver

Provides a server (via Express.js) to expose static files from the Docker host via HTTP
JavaScript
5
star
35

npm-stats-cli

A command line interface for npm statistics and insights
JavaScript
5
star
36

cfn-cognito-resource-server

A custom CloudFormation resource for Cognito Resource Servers
JavaScript
4
star
37

global-reverse-proxy

Building a global reverse proxy with on-demand SSL support on AWS
JavaScript
3
star
38

public-cloud-provider-ip-ranges

Unified datasets for public cloud provider IP ranges. Providers include AWS, Azure, CloudFlare, DigitalOcean, Fastly, Google Cloud and Oracle Cloud.
Shell
3
star
39

docker-spark-jobserver

A Docker container for Spark Jobserver
Shell
3
star
40

clair-dcos

A Docker image for running Clair on DC/OS
Dockerfile
2
star
41

docker-mesos-spark-shell

A docker image for creating a Spark shell on a Mesos cluster
Shell
2
star
42

docker-expose-socket

Docker image for exposing the Docker UNIX socket via TCP without having to reconfigure the daemon itself.
Shell
2
star
43

serverless-twitter-bot

An example application which tweets GitHub repo releases
JavaScript
1
star
44

GeoLocateURL

Node.js project to get geo information from an URL.
JavaScript
1
star
45

mesosdns-cli

A Node.js-based CLI for querying Mesos DNS service names
JavaScript
1
star
46

minio-dcos

Example on how to launch Minio in distributed mode (4 instances) on DC/OS
Shell
1
star
47

marathon-event-proxy

A proxy for the Server Sent Events endpoint of Marathon's Event Bus
JavaScript
1
star
48

docker-chronos

A Docker container for the latest Mesosphere Chronos version
Shell
1
star
49

nextjs-duckdb

Example project running for running DuckDB on Vercel
1
star
50

iterm2-ohmyzsh-config

Configuration for iTerm2 and oh-my-zsh
1
star