Lamblayer: a minimal deployment tool for AWS Lambda layers

Overview

lamblayer

lamblayer is a minimal deployment tool for AWS Lambda layers.

lamblayer does,

  • Create a Layers of built pip-installable python packages.
  • Create a Layers from local directory.
  • Update function Layers.

That's all.

Install

pip

$ pip install git+https://github.com/YU-SUKETAKAHASHI/[email protected]

Github Actions

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: YU-SUKETAKAHASHI/lamblayer@v0
        with:
          version: v0.1.0
      - run: |
          lamblayer set

Quick start

Try migrate your existing Lambda function quick_start.

$ mkdir quick_start
$ cd quick-start
$ lamblayer init --function-name quick_start
2021-12-24 10:13:41,225: [INFO]: lamblayer : v0.1.0
2021-12-24 10:13:42,132: [INFO]: starting init quick_start
2021-12-24 10:13:42,318: [INFO]: createing function.json
2021-12-24 10:13:42,319: [INFO]: completed

Now you can set layer to quick_start fuction using lamblayer set.

$ lamblayer set
2021-12-24 10:23:34,041: [INFO]: lamblayer : v0.3.0
2021-12-24 10:23:35,312: [INFO]: starting set layers to quick_start
2021-12-24 10:23:35,723: [INFO]: completed

Usage

Usage: lamblayer [OPTIONS] COMMAND [ARGS]...

  lamblayer : v0.1.0

  lamblayer is a minimal deployment tool for AWS Lambda Layers.

Options:
  --profile TEXT                  AWS credential profile
  --region TEXT                   AWS region
  --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  log level  [default: (INFO)]
  --help                          Show this message and exit.

Commands:
  create   create a layer.
  init     initialize function.json
  list     show list of the layers.
  set      set layers to function.
  version  show lamblayer's version number.

Init

Initialize set_layer.json by existing function.

Usage: lamblayer init [OPTIONS]

  initialize function.json

Options:
  --profile TEXT                  AWS credential profile
  --region TEXT                   AWS region
  --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  log level
  --function-name TEXT            function name for initialize  [default:
                                  LAMBLAYER]
  --download                      download all layers.zip, or not  [default:
                                  False]
  --help                          Show this message and exit.

lamblayer init create set_layer.json as a configration file for layers of the function.

lamblayer init --function-name your_function_name

If --download is selected, download all layer zip contents at ./{layer_name}-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.zip

Create

Create a layer of built pip-installable python packages, or from local directory.

Usage: lamblayer create [OPTIONS]

  create a layer.

Options:
  --profile TEXT                  AWS credential profile
  --region TEXT                   AWS region
  --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  log level
  --packages TEXT                 packages file path  [default:
                                  (packages.json)]
  --src TEXT                      a root directory to put in the layer.
                                  [default: (.)]
  --wrap-dir1 TEXT                a wrap directory1 name
  --wrap-dir2 TEXT                a wrap directory2 name
  --layer TEXT                    layer config file  [default: layer.json]
  --help                          Show this message and exit.
  1. pip-installable packages

Creating a layer of pip-installable python packages, spesify packages config file with --packages, and layer config file with --layer.

lamblayer create --packages packages.json --layer layer.json

Note: This option is currently not available. Coming soon!!

  1. from local directory

Creating a layer from local directory, spesify src directory with --src, and layer config file with --layer.

lamblayer create --src my_packages --layer.json

In layers, you have to place script files in the python directory, but lamblayer can handle the placing for you. You can wrap your package using --wrap-dir1 and --wrap-dir2.

ex1)

your dir tree,

.
├── layer.json
└── my_package
    ├── __init__.py
    ├── module1.py
    └── module2.py

command,

lamblayer create --src my_package --wrap-dir1 python

now, created layer dir tree.

python
├── __init__.py
├── module1.py
└── module2.py

ex2)

your dir tree,

.
├── layer.json
└── my_package
    ├── __init__.py
    ├── module1.py
    └── module2.py

command,

lamblayer create --src my_package --wrap-dir1 python --wrap-dir2 my_package

now, created layer dir tree.

python
└── my_package
    ├── __init__.py
    ├── module1.py
    └── module2.py

packages.json

packages.json is a difinition for LayerZip. These attributes will be used for LayerZip API call.

{
    "Arch": "x86_64",
    "Runtime": "py39",
    "Packages": [
        "numpy==1.20.2",
        "requests"
    ]
}

Arch (string): the instruction set architecture you want for your function code. [x86_64 | arm64]

Runtime (string): the language of your lambda that uses this layer. [py37 | py38 | py39]

Packages (list, string): the pip-installable packages name. You can specify version of package in the same way as pip install.

layer.json

layer.json is a definition for Lambda layers. JSON structure is based from PublishLayerVersion for Lambda API.

{
    "LayerName": "numpy_requests",
    "Description": "numpy==1.20.2, requests",
    "CompatibleRuntimes": [
        "python3.7",
        "python3.8",
        "python3.9"
    ],
    "LicenseInfo": ""
}

Set

Set layers to the function.

Usage: lamblayer set [OPTIONS]

  set layers to function.

Options:
  --profile TEXT                  AWS credential profile
  --region TEXT                   AWS region
  --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  log level
  --function TEXT                 function config file  [default:
                                  function.json]
  --help                          Show this message and exit.

lamblayer set changes the configration of the function for layers.

lamblayer set --set-layer set_layer.json

function.json

function.json is a definition for Lambda function. JSON structure is part of CreateFunction for Lambda API.

{
    "FunctionName": "lamblayer",
    "Layers": [
        "arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:layer:Galaxy:42",
        "lamblayer_layer"
    ]
}

If the name of layer is only passed, completes it to the ARN(Amazon Resourse Name) with the latest version number.

ex) arn:aws:lambda:{your_region}:{your_accountid}:layer:lambdarider_layer:{latest_version_number}

List

Show List of the layers.

Usage: lamblayer list [OPTIONS]

  show list of the layers.

Options:
  --profile TEXT                  AWS credential profile
  --region TEXT                   AWS region
  --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  log level
  --help                          Show this message and exit.
lamblayer list

LICENSE

MIT License

Copyright© 2021 Yusuke Takahashi

You might also like...
Automated AWS account hardening with AWS Control Tower and AWS Step Functions
Automated AWS account hardening with AWS Control Tower and AWS Step Functions

Automate activities in Control Tower provisioned AWS accounts Table of contents Introduction Architecture Prerequisites Tools and services Usage Clean

Implement backup and recovery with AWS Backup across your AWS Organizations using a CI/CD pipeline (AWS CodePipeline).
Implement backup and recovery with AWS Backup across your AWS Organizations using a CI/CD pipeline (AWS CodePipeline).

Backup and Recovery with AWS Backup This repository provides you with a management and deployment solution for implementing Backup and Recovery with A

Criando Lambda Functions para Ingerir Dados de APIs com AWS CDK

LIVE001 - AWS Lambda para Ingerir Dados de APIs Fazer o deploy de uma função lambda com infraestrutura como código Lambda vai numa API externa e extra

A python library for creating Slack slash commands using AWS Lambda Functions

slashbot Slashbot makes it easy to create slash commands using AWS Lambda functions. These can be handy for creating a secure way to execute automated

AWS SQS event redrive Lambda With Python

AWS SQS event redrive Lambda This repository contains one simple AWS Lambda function in Python to redrive AWS SQS events from source queue to destinat

AWS SQS event redrive Lambda

This repository contains the Lambda function to redrive sqs events from source to destination queue while controlling maxRetry per event.

AWS Lambda Fast API starter application

AWS Lambda Fast API Fast API starter application compatible with API Gateway and Lambda Function. How to deploy it? Terraform AWS Lambda API is a reus

A Python AWS Lambda Webhook listener that generates a permanent URL when an asset is created in Contentstack.

Webhook Listener A Python Lambda Webhook Listener - Generates a permanent URL on created assets. See doc on Generating a Permanent URL: https://www.co

AWS Lambda - Parsing Cloudwatch Data and sending the response via email.

AWS Lambda - Parsing Cloudwatch Data and sending the response via email. Author: Evan Erickson Language: Python Backend: AWS / Serverless / AWS Lambda

Releases(v0.1.0)
Owner
Yusuke Takahashi
Yusuke Takahashi
aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in a future time.

aws-lambda-scheduler aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in the future. This functionality is achieved by dyn

Oğuzhan Yılmaz 57 Dec 17, 2022
Python + AWS Lambda Hands OnPython + AWS Lambda Hands On

Python + AWS Lambda Hands On Python Criada em 1990, por Guido Van Rossum. "Bala de prata" (quase). Muito utilizado em: Automatizações - Selenium, Beau

Marcelo Ortiz de Santana 8 Sep 9, 2022
Aws-lambda-requests-wrapper - Request/Response wrapper for AWS Lambda with API Gateway

AWS Lambda Requests Wrapper Request/Response wrapper for AWS Lambda with API Gat

null 1 May 20, 2022
Building and deploying AWS Lambda Shared Layers

AWS Lambda Shared Layers This repository is hosting the code from the following blog post: AWS Lambda & Shared layers for Python. The goal of this rep

Flaneer 7 Dec 2, 2021
Lambda-function - Python codes that allow notification of changes made to some services using the AWS Lambda Function

AWS Lambda Function This repository contains python codes that allow notificatio

Elif Apaydın 3 Feb 11, 2022
SSH-Restricted deploys an SSH compliance rule (AWS Config) with auto-remediation via AWS Lambda if SSH access is public.

SSH-Restricted SSH-Restricted deploys an SSH compliance rule with auto-remediation via AWS Lambda if SSH access is public. SSH-Auto-Restricted checks

Adrian Hornsby 30 Nov 8, 2022
A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray, structured logging and creating custom metrics asynchronously easier

A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray, structured logging and creating custom metrics asynchronously easier

Amazon Web Services - Labs 1.9k Jan 7, 2023
POC de uma AWS lambda que executa a consulta de preços de criptomoedas, e é implantada na AWS usando Github actions.

Cryptocurrency Prices Overview Instalação Repositório Configuração CI/CD Roadmap Testes Overview A ideia deste projeto é aplicar o conteúdo estudado s

Gustavo Santos 3 Aug 31, 2022
AWS-serverless-starter - AWS Lambda serverless stack via Serverless framework

Serverless app via AWS Lambda, ApiGateway and Serverless framework Configuration

 Bəxtiyar 3 Feb 2, 2022