Run from the CLI
A Deta Micro can be run directly from the
deta cli using the command deta run with an input.
In order to run a micro from the cli directly, the micro's code needs to define functions that will be run from the cli with the help of our library
deta library is pre-installed on a micro and can just be imported directly.
With this code deployed on a micro, you can simply run
And see the following output:
A function that is triggered from the cli must take an
event as the only argument.
You can provide an input from the cli to the function which will be passed on as an
event. It has four attributes:
objectprovides the JSON payload
stringprovides the raw JSON payload
stringtype of an event,
runwhen running from the cli
stringthe action provided from the cli, defaults to an empty string
With this code deployed on a micro, you can run
And should see the following output.
The input to your function on a micro can be provided through the
deta cli and accessed in the code from the
event object. The input is a JSON object created from the arguments provided to the cli.
An important consideration is that the values in key-value pairs in the input are always either strings, list of strings or booleans.
Boolean flags are provided with a single dash, string arguments with double dash and if multiple values are provided for the same key, a list of strings will be provided.
will provide the micro with the following input:
You need to explicitly convert the string values to other types in your code if needed.
Actions help you run different functions based on an
action that you define for the function.
action defaults to an empty string if not provided.
With this code deployed on a deta micro, if you run
where you tell the cli to run action
"name": "deta" as input. You should see the following output:
And if you do
deta run with action
you should see the following output:
Run and HTTP
You can combine both run and HTTP triggers in the same deta micro. For this you need to instantiate your app using the
deta library that is pre-installed on a micro.
Run and Cron
You can use both run and cron triggers in the same deta micro. You can also stack run and cron triggers for the same function.