File structure when using serverless-python-requirements

Hello. I ’m Hirose from Pathee.

When using serverless-python-requirements I didn't find much information about the file structure, so I will write it.

Status

The company is developing an API using ʻAWS lambda` Part of the backend of a new project

Overview

--Language is Python3.7 --Package management is Pipenv --Development / execution / deployment using Serverless Framework --Package is layered using serverless-python-requirements --Build the development environment in Docker and perform local tests (UT etc.) in Docker

Directory structure

root
├── lambda
│   ├── env
│   │   ├── dev
│   │   │   └── resource.yml
│   │   └── prod
│   │       └── resource.yml
│   ├── handler
│   │   └── aaa #Unit of each API
│   │       └── aaa.py
│   └── serverless.yml
├── layer
│   └── package
│       ├── Pipfile # ※1
│       ├── Pipfile.lock # ※2
│       └── serverless.yml
├── stepfunctions
│   └── sf_aaa.yml
├── docker-dompose.yml
├── Dockerfile
├── Pipfile #* Symbolic Link to 1
└── Pipfile.lock #* 2 Symbolic Link

Coverage of Serverless Framework

Create

Use only

problem

Pipenv is implemented in the following two situations

--Install the package inside Docker --Create a layer with serverless-python-requirements

Because I want to use the same package in both of the above situations, I want to use a common Pipfile, but Could not specify the directory for each Pipfile

So, as a solution, put the actual situation on the person who uses it with serverless-python-requirements, In the installation inside Docker, I put a symbolic link in the above file and surpassed it

I was looking into it again to write this article, If you specify the PIPENV_PIPFILE environment variable with pipenv, make it an absolute path may solve the problem ... Actually, I built this directory structure a few months ago, and I remember trying the above at that time, but it's ambiguous ... I would like to write a follow-up report if I have time

Recommended Posts

File structure when using serverless-python-requirements
Summary when using Fabric
Precautions when using Chainer
File encryption using OpenSSL
(Personal) points when using ctypes
Environment variables when using Tkinter
DEBUG settings when using Django
When using if and when using while
Use configparser when using API
Small speedup when using pytorch
A memorandum when using beautiful soup
Proxy measures when using WEB API
Precautions when using pit in Python
Precautions when using TextBlob trait analysis
Precautions when using codecs and pandas
Precautions when using the urllib.parse.quote function
[Python] Be careful when using print
Extract the targz file using python
Precautions when using phantomjs from python
ResourceWarning when using requests: unclosed workaround
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
[Python] File operation using if statement
[VS Code] ~ Tips when using python ~
Get the file path using Pathlib
When using regular expressions in Python
Run tests automatically when saving file