Hello world (Py)

src/Index.py

First let's create a simple hello-world script. We are creating a function called handler() that will act as the entryPoint of our code. Our goal is to print a simple "hello world" to the console.

index.py
def handler(event, context):
    print('Hello World!');

If you are using visual studio code, this should look something like this:

task-config.json

Next we need to create a configuration file that the Extra Horizon CLI can use to configure and deploy your function to you cluster.

To create the our function we need to provide the following information:

  • Name of the function

  • A description

  • Reference to the directory containing the (built) code (code)

  • the entrypoint or the function that should be invoked when the function is triggered

  • the runtime you want your code to use

For our function it looks something like this:

task-config.json
{
    "name": "hello-world-python",
    "description": "python hello world example",
    "path": "src",
    "entryPoint": "index.handler",
    "runtime": "python3.9"
}

In visual studio code your project should something like this:

Deploying with the ExH CLI

You can deploy your function to the task service using the EXH CLI Tool. run the sync task command in your terminal:

exh tasks sync --path=./task-config.json

You can see a hello-world function has been created in the task service. Visit the Task service documentation for more information.

Running your task using postman

Using postman we can create a new task execution for our hello-world function. Create a http POST method and mention the function name.

Verify using the ExH Control Center

You can log into the Extra Horizon control center to verify the execution of your function.

Go to tasks>hello-world-python>executions.

Success!! 🎉You just created your first python function in Extra Horizon

Tips

When you want add dependencies to your code. You can just add them to your src folder and the CLI will upload them to the environment. Make sure to only include essential dependencies as there is a 10MB limit for the entire size of your code.

In case you need to create functions larger than 10MB you can use docker. Please contact the Extra Horizon team via support@extrahorizon.com or via your dedicated slack channel on how to deploy your docker images.

Last updated