Skip to content

πŸ“¦ Deploy microservice Python Serverless services with common code

License

Notifications You must be signed in to change notification settings

onlicar/serverless-package-common

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

serverless-package-common

πŸ“¦ Deploy microservice Python Serverless services with common code

Before deploying, this plugin symlinks folders containing shared code into the root directory of your Serverless microservice.

Installation

npm i serverless-package-common --save-dev

Usage

service: your-service

plugins:
  - serverless-package-common

functions:
  # Your functions here

custom:
  packageCommon:
    common:
      - '../common'

Example Directory Structure

my-project@1.0.0
└── common
    └── resource.py
└── my-service
    └── handler.py
    └── serverless.yml
└── other-service
    └── handler.py
    └── serverless.yml

In handler.py, common code is import like so:

from common.resource import shared_resource

Developing

To use with serverless-offline or test suites, set your PYTHONPATH to the project's root directory. You can add this script to run as offline:start in package.json.

start-offline.sh

#!/bin/bash
# Run serverless offline for a given microservice

service=${1}

if [ -z "$service" ]
    then
        echo "No service specified"
        echo "Usage: npm run offline:start <service>"
        exit
    fi
        export PYTHONPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
        echo "Setting PYTHONPATH to project root:" $PYTHONPATH

        cd $service

        serverless offline start

About

πŸ“¦ Deploy microservice Python Serverless services with common code

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published