Asynchronous Serverless Task Execution
Chili-Pepper is a simple framework that makes it easy to execute tasks without interrupting the main flow of your application. It handles serverless deployment and task execution. It allows you to run important functions in parallel with your main application with zero downtime, zero maintenance and infinite scaling.
usage: chili [-h] [--app APP] {deploy} ...
Serverless asynchronous tasks
positional arguments:
{deploy} Chili-Pepper commands
deploy Deploy functions to serverless provider
optional arguments:
-h, --help show this help message and exit
--app APP, -A APP The Chili-Pepper application location
pip install chili-pepper
Next, you need to configure your serverless provider credentials.
You can provide AWS credentials in many ways, including environment variables, your aws credentials file, or a server role. See the boto3 documentation about credential configuration for details.
These credentials need to be allowed to create, execute and delete AWS Lambda functions and IAM roles.
You will also need an S3 bucket (with versioning enabled).
Microsoft Azure Cloud is not supported at this time, but there are plans to support it in the future.
Google Cloud is not supported at this time, but there are plans to support it in the future.
The Chili-Pepper app will be used to identify and deploy your functions to the serverless cloud provider.
app = ChiliPepper(app_name="demo")
Of course, the app
variable can have any name -
we'll be calling it app
in these examples.
You need to pass these required AWS specific configs to the app. For a full list of AWS configuration options, see Aws Configuration.
app.conf["aws"]["bucket_name"] = "my-chili-pepper-bucket"
This bucket will be used for storing AWS Lambda deployment packages. You should enable versioning on the bucket.
app.conf["aws"]["runtime"] = "python3.7"
AWS Lambda supports several python runtimes. See the lambda runtime documentation for a full list. You must pass the "Identifier" for the runtime of your choice to the Chili-Pepper app config.
You can use the Chili-Pepper app to identify tasks that should be run.
@app.task()
def my_task(event, context):
return f"Hello {event['name']}!"
Before you can asynchronously call your task, you must deploy it to your cloud provider.
chili deploy --app my_module.tasks.app
Calling deploy will create a zipfile containing your code as well as any python dependencies. Chili-Pepper will then use upload that zipfile to your S3 bucket, and use Cloudformation to create an AWS Lambda function for each of the tasks you identified with the app.task() decorator.
Now that you've deployed your tasks to the cloud, you can call them asynchronously.
task_result = my_task.delay({"name": "Jalapeno"})
print(task_result.get())
This will print Hello Jalapeno!
,
after executing my_task in a serverless function.
Chili-Pepper is built by a 1 person team supported by these awesome backers, supporters and sponsors. If you use Chili-Pepper, I would love to hear from you! And, if I have earned your support, please consider backing me on Patreon.
.. toctree:: :maxdepth: 1 :caption: Contents: config API Docs <modules> backers license