Giter VIP home page Giter VIP logo

sls-py-tmpl's Introduction

Serverless Python Template

This repo is intended as a better alternative to the built-in AWS Python templates in serverless.

What's included?

This template includes a few of my favorite things for working with Python & Serverless:

It also has a tweaked serverless.yml file featuring:

  • custom variable syntax that allows using the default syntax AND ${AWS::AccountId} CloudFormation-style variables
  • A better IAM example - resources needed for using SSM Parameter store!
  • Add custom section with useful workarounds sls var limitations
  • A few other minor tweaks

Getting started

$ # if you don't have them installed, ensure you have serverless & pipenv
$ npm i -g serverless ; pip install pipenv
$ # Clone the template using the
$ serverless create -u https://github.com/dschep/sls-py-tmpl -n project-name
Serverless: Downloading and installing "sls-py-tmpl"...
Serverless: Successfully installed "project-name" 
$ cd project-name
$ # Create virtualenv and install dependencies
$ pipenv install
Creating a virtualenv for this project…
Using /usr/bin/python3.6m to create virtualenv…
β ‹Running virtualenv with interpreter /usr/bin/python3.6m
Using base prefix '/usr'
New python executable in /home/dschep/.local/share/virtualenvs/sls-py-tmpl-bdJKnR1O/bin/python3.6m
Also creating executable in /home/dschep/.local/share/virtualenvs/sls-py-tmpl-bdJKnR1O/bin/python
Installing setuptools, pip, wheel...done.]

Virtualenv location: /home/dschep/.local/share/virtualenvs/sls-py-tmpl-bdJKnR1O
Installing dependencies from Pipfile.lock (c44045)…
  🐍   β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 1/1 β€” 00:00:00
To activate this project's virtualenv, run the following:
 $ pipenv shell

$ # Test the sample lambda locally (sls is an included alias for serverless)
$ pipenv run sls invoke local -f hello
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}
$ # Deploy to AWS!
$ sls deploy
Serverless: Generating requirements.txt from Pipfile...
Serverless: Installing required Python packages with python3.6...
Serverless: Linking required Python packages...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Unlinking required Python packages...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (19.72 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.........
Serverless: Stack update finished...
Service Information
service: project-name
stage: dev
region: us-east-1
stack: project-name-dev
api keys:
  None
endpoints:
  None
functions:
  hello: project-name-dev-hello
$ # Invoke!
$ sls invoke -f hello
{
    "statusCode": 200,
    "body": "{\"message\": \"Go Serverless v1.0! Your function executed successfully!\", \"input\": {}}"
}

sls-py-tmpl's People

Contributors

dependabot-support avatar dschep avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.