Getting started with pebl
How to deploy a python application with a single line of code
In this quick tutorial, I want to show a super easy way to create a serverless python deployment using pebl. Unlike other infrastructure-as-code tools, pebl doesn't require external configuration yaml or json configuration files.
Instead you simply incorporate pebl like any other python library into your application, then call the methods that give your application cloud capabilities!
TLDR
As an overview (and to serve as a quick reference), here's what we're working towards. A single method to transform your python application into a cloud deployment:
import pebl
from flask import Flask
app = Flask(__name__)
@app.route("/")
def root():
return "hello, world!"
pebl.service(app, "your-subdomain.pebl.rocks")
Setup
Make sure that you have docker installed locally
Head over to pebl and create a free account
Make sure to claim your free
*.pebl.rocks
subdomain, we'll use this for the tutorial! The examples will showhey.pebl.rocks
, but make sure to put your subdomain instead.Follow these steps to install the pebl cli
Project
Now it's time to create your project!
Create a new scratch folder for this tutorial
mkdir scratch-folder
Inside the scratch folder, create a
Dockerfile
with this content:FROM peblcloud/python:0.0.8 COPY main.py . RUN pip install Flask ENTRYPOINT python -u main.py
Finally, create a
main.py
that will contain your Flask application. Make sure you place the correct*.pebl.rocks
subdomain that you claimed!import pebl from flask import Flask app = Flask(__name__) @app.route("/") def root(): return "Hello!" pebl.service(app, "your-subdomain.pebl.rocks")
Running Locally
You can try running this project locally using the pebl cli.
Start a local cluster with
pebl up
Make sure to have docker running!
Navigate to the project folder then execute
pebl run
Once running, check the state of the cluster with
pebl info
(You can exit the info pane by pressing
q
or withctrl-c
)Send a request to the running application with
curl
, taking note of the port that your endpoint is bound to. In my example we are bound to:32771
, so the curl request would be:curl localhost:32771
Running in the cloud
Now running this project in the cloud is just two steps:
Make sure you are authed with
pebl auth
Run
pebl deploy
within your project
Once deployed, you can curl your endpoint. Make sure to use https!
And with that you have successfully created a serverless deployment, complete with DNS updates, HTTPS, autoscaling, and more.
Next steps
You can see the logs and more information about your deployment by heading over to the pebl console.
To make changes, simply update the
main.py
and re-runpebl deploy
!You can also check out some more methods available for you to unlock cloud capabilities, like redis and scheduled tasks. https://docs.pebl.io/reference/SDK