Giter Site home page Giter Site logo

yasircodingcrafts / lambda_layer_easy_setup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jcorrado76/lambda_layer_easy_setup

0.0 0.0 0.0 93 KB

This repo will serve to simplify the steps to generate a compatible zip archive for creating AWS Lambda layers. With some additional changes, it can also be used to simplify the creation of a full lambda function from the generated zip archive.

Makefile 72.46% Dockerfile 27.54%

lambda_layer_easy_setup's Introduction

Lambda Layer Easy Setup


The purpose of this repo is to simplify the process of making lambda layers.

Most tutorials on creating lambda functions or lambda layers from a .zip archive involve a lot of hacking, dealing with binaries compiled on the wrong architecture, and messing around with wheel files or virtual environments.

In this repo, we seek to remove the entire "hacking" process by simply doing the whole archive generation process inside a docker container. In that environment, your installation commands become as simple as system installing something on your local machine, not even inside a virtual environment.

The directory structure for this repo looks like:

lambda_layer_easy_setup
├── Dockerfile - create a thin docker image on top of the base lambda runtime
├── Makefile - abstract away the shell commands for running docker commands and zip commands; also provides some helper commands to introspect the contents and size of your archive
├── README.md
└── layer - this is the working area for the generated dependencies and zip archive
    ├── example_unzip - this is a directory for unzipping the dependencies to check they unzip in the correct paths
    ├── python - this is the directory whose directry contains the correct structure expected by lambda 
    ├── python_numpy_layer.zip - this is the zip archive that will be uploaded to create a lambda layer
    └── requirements.txt - this is where you'll enter your requirements

Dependencies


The dependencies of this repo are:

  • the docker CLI installed on your machine
  • access to the internet to pull the AWS Lambda image and to pip install requirements from PyPI
  • make

Usage


First, you need to build the custom docker image:

make image

This uses the image target inside the Makefile to run a docker build command. The default name of the docker image is create-lambda-layer, which is configurable by going into the Makefile and changing the value for the DOCKER_IMAGE_NAME variable.

To check that the image was successfully created, you can run:

make check_image

Currently, the ECR URI for the Python 3.9 lambda function is hard coded as the AWS_LAMBDA_IMAGE_NAME variable in the Makefile. If you want to specify a new ECR URI, you just change this variable in the Makefile.

Then, you need to populate a requirements.txt in the layer directory with your requirements.

Finally, you run:

make layer

This will generate a file by the name specified in the ZIP_FILE_NAME variable in the Makefile. This is the zip file you'll upload to the layer.

There is a maximum size on the unzipped size of your layer code - it cannot be more than 250MB. If you need something bigger, then it's possible to create your own docker image, and have an unzipped size of up to 10 GB. But in this case, you'll need an image repository, and you'll need to deploy the entire image to the Lambda.

This repo can probably be worked with to start off the creation of an entire custom Lambda image.

If you want to see the size of your output zip archive, you can run:

make zip_size

lambda_layer_easy_setup's People

Contributors

jcorrado76 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.