openfunction

This Plugin can be configured on a Route and requests will be sent to the configured OpenFunction API endpoint as the upstream.

Attributes

note

The timeout attribute sets the time taken by the OpenFunction to execute, and the timeout for the HTTP client in APISIX. OpenFunction calls may take time to pull the runtime image and start the container. So, if the value is set too small, it may cause a large number of requests to fail.

Before configuring the plugin, you need to have OpenFunction running. Installation of OpenFunction requires a certain version Kubernetes cluster. For details, please refer to .

You’ll need to push your function container image to a container registry like Docker Hub or Quay.io when building a function. To do that, you’ll need to generate a secret for your container registry first.

Enable the Plugin

You can now configure the Plugin on a specific Route and point to this running OpenFunction service:

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. "uri": "/hello",
  3. "plugins": {
  4. "openfunction": {
  5. "function_uri": "http://localhost:3233/default/function-sample/test",
  6. "authorization": {
  7. }
  8. }
  9. }
  10. }'

Once you have configured the plugin, you can send a request to the Route and it will invoke the configured function:

  1. hello, test!

Configure Path Transforming

The OpenFunction Plugin also supports transforming the URL path while proxying requests to the OpenFunction API endpoints. Extensions to the base request path get appended to the function_uri specified in the Plugin configuration.

openfunction - 图2IMPORTANT

The uri configured on a Route must end with * for this feature to work properly. APISIX Routes are matched strictly and the * implies that any subpath to this URI would be matched to the same Route.

The example below configures this feature:

    Disable Plugin

    To disable the openfunction Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

    1. curl http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
    2. {
    3. "methods": ["GET"],
    4. "uri": "/index.html",
    5. "upstream": {
    6. "type": "roundrobin",
    7. "nodes": {
    8. "127.0.0.1:1980": 1
    9. }
    10. }