Today, we’re excited to announce the ability of the Oracle Cloud Infrastructure Notifications service to trigger Oracle Functions.
Oracle Functions is a functions-as-a-service (FaaS) platform that makes it easy for developers to write code that meets business needs without worrying about infrastructure. Oracle Functions manages the underlying infrastructure and scales it elastically to handle incoming service requests. When you use Oracle Functions, you’re billed only for the resources that are consumed when the function runs.
Notifications is a cloud-native messaging service that allows push-based messaging to email, PagerDuty, and HTTPS endpoints. The Notifications service provides first-class integrations with other Oracle Cloud Infrastructure services, such as Events and Monitoring. You can use these integrations to configure a Notifications service topic to deliver notifications of events and alarms to multiple endpoints, like email and PagerDuty, in a fan-out pattern.
In today’s cloud-enabled world, you expect your services to always be available. Quickly fixing issues in your cloud infrastructure is key to achieving this objective and is a part of a mature DevOps culture. But imagine your service on-call having to wake up at 3 a.m. to accomplish a simple task like resizing a compute instance to a shape with more memory. We believe in improving our customers’ experience so they can spend more time on productive things. With Notifications triggers for functions, you can now automate this scenario by writing code that resizes the compute instance.
Following are more sample use cases that you can accomplish with this integration:
If you use Oracle Cloud Infrastructure Notifications, you can use this feature in the Console, SDK, CLI, and API when creating a subscription. The following are some examples to help you get started.
When you create a subscription on a topic, select Function as the protocol type.
Then, select the compartment of the function and the function that you want to trigger.
After the function subscription is created, it appears in the Console.
From the Monitoring page of the Console, click Alarm Definitions and then click Create Alarm.
Provide the necessary information for the alarm.
Then, create a notification on the alarm that points to the topic you created a subscription for.
Create a function subscription:
oci ons subscription create \
--compartment-id "<compartment-ocid>" \
--topic-id "<topic-ocid>" \
--protocol "ORACLE_FUNCTIONS" \
--subscription-endpoint "<function_ocid>"
Create a function subscription:
subscription = client.createSubscription(CreateSubscriptionRequest.builder()
.createSubscriptionDetails(CreateSubscriptionDetails.builder()
.compartmentId(compartmentId)
.topicId(topicId)
.protocol("ORACLE_FUNCTIONS")
.endpoint(functionId)
.build())
.build()).getSubscription();
Configure the protocol in your provider configuration as follows:
variable "subscription_protocol" {
...
default = "ORACLE_FUNCTIONS"
...
...
}
Then, you can create a subscription with type Oracle_Functions:
resource "oci_ons_subscription" "test_subscription" {
#Required
compartment_id = "${var.compartment_OCID}"
endpoint = "${var.function_OCID}"
protocol = "${var.subscription_protocol}"
topic_id = "${oci_ons_notification_topic.test_notification_topic.id}"
#Optional
defined_tags = "${map("${oci_identity_tag_namespace.tag_namespace1.name}.${oci_identity_tag.tag1.name}", "${var.subscription_defined_tags_value}")}"
freeform_tags = "${var.subscription_freeform_tags}"
}
data "oci_ons_subscriptions" "test_subscriptions" {
#Required
compartment_id = "${var.compartment_ocid}"
#Optional
topic_id = "${oci_ons_subscription.test_subscription.topic_id}"
}
You can find the complete set of Notifications service Terraform examples on GitHub.
Create a function subscription:
POST /20181201/subscriptions
Host: notification.<oracle-cloud-infrastructure-region>.oraclecloud.com
<authorization and other headers>
{
"topicId": "<topic_OCID>",
"compartmentId": "<compartment_OCID>",
"protocol": "ORACLE_FUNCTIONS",
"endpoint": "<function_OCID>"
}
There’s no additional charge to trigger a function from the Notifications service. Function rates are provided on the Oracle Functions product page.
For more information about this feature and the Notifications service, see the following resources: