AWS Layer Creation Script for python

ZIP by executing PIP in Lambda's Docker container. A script that publishes it as an AWS Lambda Layer.

--Doker installation required (PIP in lambci / lambda image) --Please configure AWS in advance. --Save the following source code as a file (publish.sh) and grant execute permission. `` `chmod + x publish.sh --Execute by specifying parameters (param1 = layer-name, param2 = lib-name, param3 = lib-version, param4 = python-version) -./publish.sh requests-python37 requests 2.22.0 python3.7``` --If you specify the same Layer-name and re-execute, a new layer-version will be created.

It's not easy to make, but it works. .. .. Please when you do not want to pollute the environment at hand.

# 
# Require: docker installed.
# Require: aws config for publishing lambda layer
# 
# 1. in container, pip install python liblary and zip,
# 2. publish to aws layer
#
# Usage: param1=layer-name, param2=lib-name, param3=lib-version, param4=python-version
#  ex ```./publish.sh requests-python37 requests 2.23.0 python3.7```

layername=$1 # requests-python37
lib=$2       # requests
ver=$3       # 2.23.0
env=$4       # python3.7

zip=$lib-$ver-$env.zip # requests-2.23.0-python3.8.zip
echo packing: $zip

# Prepare
mkdir -p build
rm -rf build/* # Clean up

# pip and zip in docker.
docker run --rm -it  \
    --volume `pwd`/build:/tmp/build  \
    --workdir /tmp/build \
    lambci/lambda:build-$env \
    bash -c "pip3 install $lib==$ver -t /tmp/build/python && zip -qr $zip python/ && rm -rf /tmp/build/python && chown -R `id -u`:`id -g` ./*"

echo packed : build/$zip

aws lambda publish-layer-version \
    --layer-name $layername \
    --zip-file fileb://`pwd`/build/$zip \
    --description $zip \
    --compatible-runtimes $env

Recommended Posts

AWS Layer Creation Script for python
Create a Layer for AWS Lambda Python with Docker
Python script for ldapsearch base64 decode
boto3 (AWS SDK for Python) Note
[For Python] Quickly create an upload file to AWS Lambda Layer
Driver script for parametrically calculating Python scripts
[Python] Script useful for Excel / csv processing
WebApi creation with Python (CRUD creation) For beginners
2016-10-30 else for Python3> for:
Script python file
python script skeleton
Python script profiling
Import python script
Play with Lambda layer (python) for about 5 minutes
Periodically execute Python Script on AWS Data Pipeline
Call Polly from the AWS SDK for Python
Authentication information used by Boto3 (AWS SDK for Python)
About Python for loops
[BigQuery] How to use BigQuery API for Python -Table creation-
Image collection Python script for creating datasets for machine learning
Python basics ② for statement
Fleet provisioning with AWS IoT SDK for Python v2
python textbook for beginners
Slack chatbot creation Python
Refactoring tools for Python
DynamoDB Script Memo (Python)
Support for Python 2.7 runtime on AWS Lambda (as of 2020.1)
python for android Toolchain
Script to easily create a client device environment for AWS IoT (Python v2 version)
AWS CDK with Python
AWS SDK for Python (Boto3) development in Visual Studio 2017
Use AWS SDK for Python (boto) under Proxy environment
OpenCV for Python beginners
Install Python (for Windows)
[Python] for statement error
Python environment for projects
Run AWS IoT Device SDK for Python on Raspberry Pi
[AWS] Try adding Python library to Layer with SAM + Lambda (Python)
I wrote an empty directory automatic creation script in Python
Create a Python script for Wake on LAN (NAT traversal Wake on LAN [5])
[Python] Introduction to graph creation using coronavirus data [For beginners]
Python memo (for myself): Array
About Fabric's support for Python 3
Python list, for statement, dictionary
Python for Data Analysis Chapter 4
[Python] Scraping in AWS Lambda
Modern Python for intermediate users
Learning flow for Python beginners
Python 3.6 installation procedure [for Windows]
POST json with Python3 script
AWS CDK-Lambda + API Gateway (Python)
BigQuery integration for Python users
Python learning plan for AI learning
Set Up for Mac (Python)
Bitcoin price monitor python script
Run illustrator script from python
Search for strings in Python
Python Tkinter notes (for myself)
OpenCV3 installation for Python3 @macOS
Python code memo for yourself
Python environment construction For Mac