Hello world (Py)
Last updated
Last updated
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.
If you are using visual studio code, this should look something like this:
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:
In visual studio code your project should something like this:
You can deploy your function to the task service using the EXH CLI Tool. run the sync task command in your terminal:
You can see a hello-world function has been created in the task service. Visit the Task service documentation for more information.
Using postman we can create a new task execution for our hello-world function. Create a http POST method and mention the function name.
You can log into the Extra Horizon control center to verify the execution of your function.
Go to tasks>hello-world-python>executions.
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.
Success!! You just created your first python function in Extra Horizon