[Python / AWS Lambda layers] I want to reuse only module in AWS Lambda Layers

Overview

There was no article that only pinpointed what I wanted to do, so I created it as a memo

It's almost the same as the method of the article Common library with AWS Lambda Layers, but ** pip install without including any self-made source. If you want to reuse only the module on lambda ** I couldn't find it even if I searched for the method, so I made an article. (Because I want to use it many times!)

procedure

1. Zip the modules into a zip

$ mkdir python

#If you have any other modules you want, put them all in your python directory
$ pip install module_name -t ./python

#Layer the contents of the python directory.Compress to zip
$ zip -r layer.zip python/

2. Upload to S3

Make the S3 bucket first

(1) When using GUI

Omitted as it is easy to upload in the AWS console of the GUI

(2) When using the command line

When the file size is large or the communication line is poor (!), It will fail unless uploaded via the command line.

Install aws-cli v2 and execute the following command on it.

#Check backet name
$ aws s3 ls
2019-05-07 19:04:54 xxxxxxxxxxxxx # <=Bucket name

#Upload to s3
#aws s3 cp File name you want to upload Bucket name
$ aws s3 cp ./layer.zip s3://xxxxxxxxxxxxx

Wait (˘ω˘)

3. Create layers

4. Call layer from your lambda function

For 3 and 4, Add Layer to Lambda Function in the article introduced in Overview earlier. A2% E6% 95% B0% E3% 81% ABlayer% E3% 82% 92% E8% BF% BD% E5% 8A% A0% E3% 81% 99% E3% 82% 8B) I was fine.

(Sorry for the miscellaneous. Thank you very much to @t_okkan for creating the article!)

Recommended Posts

[Python / AWS Lambda layers] I want to reuse only module in AWS Lambda Layers
I want to AWS Lambda with Python on Mac!
I want to play with aws with python
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
I want to do Dunnett's test in Python
I was able to recurse in Python: lambda
I want to create a window in Python
I want to merge nested dicts in Python
I want to display the progress in Python!
I want to do a monkey patch only partially safely in Python
I want to write in Python! (1) Code format check
I want to embed a variable in a Python string
I want to easily implement a timeout in python
[Python] Scraping in AWS Lambda
I want to write in Python! (2) Let's write a test
Even in JavaScript, I want to see Python `range ()`!
I want to randomly sample a file in Python
I want to work with a robot in python.
I want to write in Python! (3) Utilize the mock
I was able to repeat it in Python: lambda
I want to use the R dataset in python
I want to do something in Python when I finish
I want to manipulate strings in Kotlin like Python!
I want to do something like sort uniq in Python
I want to be able to run Python in VS Code
I want to make input () a nice complement in python
I didn't want to write the AWS key in the program
Write AWS Lambda function in Python
I want to debug with Python
I compared Node.js and Python in creating thumbnails using AWS Lambda
I tried to implement PLSA in Python
I want to print in a comprehension
I tried to implement PLSA in Python 2
I want to use jar from python
I want to build a Python environment
I want to analyze logs with Python
I tried to implement ADALINE in Python
Module to generate word N-gram in Python
I wanted to solve ABC159 in Python
I tried to implement PPO in Python
Connect to s3 with AWS Lambda Python
I want to embed Matplotlib in PySimpleGUI
I want to do it with Python lambda Django, but I will stop
I want to convert a table converted to PDF in Python back to CSV
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
Environment maintenance made with Docker (I want to post-process GrADS in Python
I want to color a part of an Excel string in Python
Upload what you got in request to S3 with AWS Lambda Python
[Lambda] I tried to incorporate an external module of python via S3
I want to use MATLAB feval with python
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
3 steps to put Python + mecab in yum only
I want to make a game with Python
I want to store DB information in list
Use cryptography module to handle OpenSSL in Python
I tried to implement TOPIC MODEL in Python
I want to use Temporary Directory with Python2
To add a module to python put in Julialang
I want to use ceres solver from python