1.0.2 ā€¢ Published 9 months ago

sls-py-extern-pkgs v1.0.2

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

sls-py-extern-pkgs šŸ“¦

serverless

npm version

Package a Serverless Python Function services with external code

Installation

npm i -D sls-py-extern-pkgs
yarn add -D sls-py-extern-pkgs

Usage

service: service-name

plugins:
  - serverless-package-external

ecr:
  images:
    # Your images here
    # TODO: Currently it doesn't work, but the packages are copied

functions:
  # Your functions here

custom:
  packageExternal:
    common_utils:
      # Optional command to run after you have linked common_utils
      cmd: pip install -r requirements.txt -t .. > /dev/null 2>&1
      source: '../common_utils'
      # if no functions specified, it will apply it to all
      functions:
        - service-a
        - service-b
    api_utils:
      source: '../api_utils'
      functions:
        - service-b

Example Directory Structure

ā””ā”€ā”€ common_utils
    ā””ā”€ā”€ resource.py
ā””ā”€ā”€ api_utils
    ā””ā”€ā”€ resource.py
ā””ā”€ā”€ functions
  ā””ā”€ā”€ service-a
      ā””ā”€ā”€ handler.py
  ā””ā”€ā”€ service-b
      ā””ā”€ā”€ handler.py
  serverless.yml

In service-b/handler.py, external code can be imported:

from common_utils.resource import shared_resource
from api_utils.resource import shared_resource