Create a Function

The first step in creating your own Function is coding it. Currently, you can do this using Python or Go by choosing the appropriate language template. Each template gives you a basic structure, and you can use auxiliary functions to refactor your code, making sure the main Function is there. Please don't rename the main Function or change its definition.

This main Function receives all the information from the HTTP request made to invoke the Function:
  • Path
  • Method (POST, GET, PUT, PATCH or DELETE)
  • Headers
  • Query parameters
  • Body

This information is the data you can provide to your Function.

When the task of your Function has finished, you may want to return some result or feedback in your response. For this you can:
  • Set a status code
  • Use the response body
  • Add headers to the response

The details on how to get the request data and how to set the response info is language and template specific, so check the documentation about the template you want to use to build your Function.

  1. Under User Functions, click Functions.
  2. Click New Function.


  3. Complete the following fields:
    1. Function Name: choose it carefully as you won't be able to update it once the Function is built.
    2. Enabled button: enable/disable the Function. This allows you to disable a Function so it won't be consuming resources (Altair Units won't be consumed while the Function is disabled). This way, you can have multiple Functions created for testing, they can interact with the code (create,update and delete) but the Function can't be invoked until it is enabled.
    3. Description: optional field to describe the purpose of the Function.
    4. Resources: set the resources in terms of CPU, memory and limits for the pods. Default values are set automatically, and you can update those any time, based on the information obtained from the metrics of the function.
      Figure 1.


  4. From the Template drop down menu, choose the type of Function you want to code:
    • FMU: Upload an FMU file to run a simulation model
    • Go: Code your serverless Function using Go language
    • Python: Code your serverless Function using Python language
  5. If you choose to run a simulation model by using a FMU, upload the FMU file and click Save. Go to Upload an FMU File to Run a Simulation Model.
  6. If you choose to code your serverless function (either using Go or Python language), a template for the code appears in the panel. The Libraries drop-down menu displays the available libraries you can use while coding. To use any library, select it from the list provided.
    Note: This action will allow you to add it to your template, but you will still need to add the import line to your code. The libraries added by default follow the same behaviour; imports need to be added to your code.
    Figure 2.