Skip to content
View NOOBPOOK's full-sized avatar
🎯
Focusing
🎯
Focusing
  • NOOBPOOK

Block or report NOOBPOOK

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Please don't include any personal information such as legal names or email addresses. Maximum 100 characters, markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
NOOBPOOK/README.md

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 Serverless Framework.

This template configures a single function, api, which is responsible for handling all incoming requests thanks to configured http events. To learn more about http event configuration options, please refer to http event docs. As the events are configured in a way to accept all incoming requests, Flask framework is responsible for routing and handling requests internall y. 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

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" to stage "dev" (us-east-1)

Using Python specified in "runtime": python3.12

Packaging Python WSGI handler...

✔ Service deployed to stack aws-python-flask-api-dev (104s)

endpoints:
  ANY - https://xxxxxxxxxe.execute-api.us-east-1.amazonaws.com/dev/
  ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/{proxy+}
functions:
  api: aws-python-flask-api-dev-api (41 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 http 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!" }

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.

Popular repositories Loading

  1. Shortest-Job-First Shortest-Job-First Public

    Python code which provides direct answer for your OS SJF scheduling Algorithm

    Python 3

  2. Unisigned-Binary-Table-Algorithm Unisigned-Binary-Table-Algorithm Public

    With the help of C++ language, we have made unsigned binary algorithm table which is valid up to 128 x 128 decimal number calculation.

    C++ 2

  3. Priority-Scheduling Priority-Scheduling Public

    This code gives direct output along with Gnatt chart by following the rules of priority scheduling algorithm.

    Python 2

  4. Round-Robin-Scheduling Round-Robin-Scheduling Public

    This code gives direct output along with Gnatt chart for RoundRobin Scheduling Algorithm

    Python 2

  5. DECIMAL-TO-OTHER-BASES DECIMAL-TO-OTHER-BASES Public

    This program converts decimal number into other numbers (Hexa,Octa,Binary) and also shows the steps for the same!

    Python 1

  6. OTHERBASE-TO-DECIMAL OTHERBASE-TO-DECIMAL Public

    This program converts other types of numbers (Octa,Hexa,Binary) into Decimal form and also shows the steps for the same!

    Python 1