Edit your function

This page will walk you through editing a Binaris function and reading the execution logs after invocation.

If you are new to Binaris it is recommended that you begin with the previous tutorial:

Note: the instructions below assume you are using MacOS, Ubuntu or Debian.

Function.py

The bn create python2 hello command that you used in the previous getting-started tutorial creates a file called function.py locally.

def handler(body, req):
    name = req.query.get('name') or body.get('name') or 'World'
    return 'Hello {}!'.format(name)

The function receives two arguments. body holds the HTTP request body, and req holds HTTP request parameters (such as query strings and headers). Objects returned from a function are automatically JSON-ified and sent as the HTTP response body.

Read more about function signatures in the reference.

Modify the code

Change the function.py file for the hello function.

- return 'Hello {}!'.format(name)
+ return 'Howdy {}!'.format(name)

After updating the code the function will need to be deployed again.

$ bn deploy hello
Deployed function hello
Invoke with one of:
  "bn invoke hello"
  "curl -H X-Binaris-Api-Key:$(bn show apiKey) https://run.binaris.com/v2/run/<Your_Account_Number>/hello"

Next, invoke the function to test the changes:

$ bn invoke hello
"Howdy World!"
$ bn invoke hello --data '{"name": "Binaris"}'
"Howdy Binaris!"

Tip

You can use bn --help to see all the available CLI commands.

What’s next:

Cloud logs