Code Monkey home page Code Monkey logo

stripe-checkout-session-handler's Introduction

Serverless Framework Python Flask API on AWS

This template demonstrates how to develop and deploy a simple Python Flask API service running on AWS Lambda using the traditional Serverless Framework.

Anatomy of the template

This template configures a single function, api, which is responsible for handling all incoming requests thanks to configured httpApi events. To learn more about httpApi event configuration options, please refer to httpApi event docs. As the events are configured in a way to accept all incoming requests, Flask framework is responsible for routing and handling requests internally. The implementation takes advantage of serverless-wsgi, which allows you to wrap WSGI applications such as Flask apps. To learn more about serverless-wsgi, please refer to corresponding GitHub repository. Additionally, the template relies on serverless-python-requirements plugin for packaging dependencies from requirements.txt file. For more details about serverless-python-requirements configuration, please refer to corresponding GitHub repository.

Usage

Prerequisites

In order to package your dependencies locally with serverless-python-requirements, you need to have Python3.8 installed locally. You can create and activate a dedicated virtual environment with the following command:

python3.8 -m venv ./venv
source ./venv/bin/activate

Alternatively, you can also use dockerizePip configuration from serverless-python-requirements. For details on that, please refer to corresponding GitHub repository.

Deployment

This example is made to work with the Serverless Framework dashboard, which includes advanced features such as CI/CD, monitoring, metrics, etc.

In order to deploy with dashboard, you need to first login with:

serverless login

install dependencies with:

npm install

and

pip install -r requirements.txt

and then perform deployment with:

serverless deploy

After running deploy, you should see output similar to:

Deploying aws-python-flask-api-project to stage dev (us-east-1)

โœ” Service deployed to stack aws-python-flask-api-project-dev (182s)

endpoint: ANY - https://xxxxxxxx.execute-api.us-east-1.amazonaws.com
functions:
  api: aws-python-flask-api-project-dev-api (1.5 MB)

Note: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to httpApi event docs.

Invocation

After successful deployment, you can call the created application via HTTP:

curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/

Which should result in the following response:

{"message":"Hello from root!"}

Calling the /hello path with:

curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/hello

Should result in the following response:

{"message":"Hello from path!"}

If you try to invoke a path or method that does not have a configured handler, e.g. with:

curl https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/nonexistent

You should receive the following response:

{"error":"Not Found!"}

Local development

Thanks to capabilities of serverless-wsgi, it is also possible to run your application locally, however, in order to do that, you will need to first install werkzeug dependency, as well as all other dependencies listed in requirements.txt. It is recommended to use a dedicated virtual environment for that purpose. You can install all needed dependencies with the following commands:

pip install werkzeug
pip install -r requirements.txt

At this point, you can run your application locally with the following command:

serverless wsgi serve

For additional local development capabilities of serverless-wsgi plugin, please refer to corresponding GitHub repository.

stripe-checkout-session-handler's People

Watchers

George Roros 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.