Creating a Function Subscription

Create a function subscription in Notifications.

Use a function subscription to invoke and run a function when a triggering condition occurs.

When the configured triggering condition occurs, an alarm, announcement subscription, event rule, connector, or contextual notification (alarm or event rule) sends (publishes) a message  to the configured topic, and Notifications delivers that message to active subscriptions in the topic. On receipt of the message, the function is invoked and run. For an example scenario, see Scenario A: Automatically Resizing VMs.

The Notifications service has no information about a function after it's invoked. For details, see the troubleshooting information in Function Not Invoked or Run.

Before You Begin

You must have FN_INVOCATION permission against the function to be able to add the function as a subscription to a topic. See Add a Function Subscription in Securing Notifications.

  • These steps show how to open the Create Subscription panel from the details page for the topic that you want to add the subscription to. You can also open this panel from the Subscriptions list page, specifying the topic in the panel: Select Create Subscription, and then select a Subscription Topic.
    1. On the Topics list page, select the topic that you want to work with. If you need help finding the list page or the topic, see Listing Topics.
    2. On the topic's details page, select Create Subscription.
    3. In the Create Subscription panel, for Protocol, select Function.
    4. Select the compartment and application that contain the function that you want, and then select the function.
    5. Select Create.

    Notifications creates the function subscription. Confirmation isn't required for function subscriptions.

  • Use the oci ons subscription create command and required parameters to create a function subscription:

    oci ons subscription create --protocol "ORACLE_FUNCTIONS" --subscription-endpoint <function_OCID> [...]

    For a complete list of parameters and values for CLI commands, see the Command Line Reference for Notifications.

  • Run the CreateSubscription operation to create a function subscription.

    Example:

    POST /20181201/subscriptions
    Host: notification.us-phoenix-1.oraclecloud.com
    <authorization and other headers>
    {
      "topicId": "<topic_OCID>",
      "compartmentId": "<compartment_OCID>",
      "protocol": "ORACLE_FUNCTIONS",
      "endpoint": "<function_OCID>"
    }

What's Next

Although a new subscription must be in the same compartment as its parent topic, you can move it to another compartment after creation. See Moving a Subscription.