![](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/File/7a6518d9db208ff586144e7e49b9d31c/0_oracle_notification_service_functions_serverless_hero_image.png)
Oracle Cloud Infrastructure NotificationsサービスからOracle Functionsをトリガーできるようになりました。
Oracle Functionsはfunctions as a service(FaaS)プラットフォームで、これを使うことで開発者はインフラについて心配することなくビジネス上の要求に見合ったコードを書くことができます。Oracle Functionsが下回りのインフラをマネージし、エラスティックにスケールして受け取ったリクエストをさばきます。Oracle Functionsを使う際にかかる料金は、そのファンクションが実行している間だけのリソースに対してです。
Notificationsはクラウドネイティブなメッセージングサービスで、Eメール、PagerDutyおよびHTTPSエンドポイントに対してのプッシュベースのメッセージングをサポートしてきました。NotificationsはEventsやMonitoringのような他のOracle Cloud Infrastructure 上のサービスとの最上級のインテグレーションを提供します。こうしたインテグレーションを使い、ある通知トピックからイベント通知やアラーム通知をEメールやPagerDutyといった複数のエンドポイントに発出できます。Oracle Functionsはfunctions as a service(FaaS)プラットフォームで、これを使うことで開発者はインフラについて心配することなくビジネス上の要求に見合ったコードを書くことができます。Oracle Functionsが下回りのインフラをマネージし、エラスティックにスケールして受け取ったリクエストをさばきます。Oracle Functionsを使う際にかかる料金は、そのファンクションが実行している間だけのリソースに対してです。
一般的なユースケース
今日のクラウドが普及した世界では、あなたは自身のサービスが常に利用可能であることを期待するでしょう。クラウドインフラ上で起きた問題を迅速に解決することは、この目標を実現するうえで鍵であり、また、成熟したDevOpsのカルチャーの一部です。あなたがオンコールエンジニアで、あなたのサービスに対して必要なごくシンプルなタスク、例えばコンピュートインスタンスのシェイプにメモリを追加してやるといったようなタスクのために早朝3時に起こされるような場面を想像してみてください。我々はこのようなシナリオを自動化することで、カスタマーエクスペリエンスを向上し、また、お客様がもっと多くの時間を生産的な仕事に使うことができるようになると信じています。Notificationsによってコンピュートインスタンスをリサイズするように書いておいたコードのファンクションをトリガーすることで、このシナリオを自動化することができるんです。
以下はこのインテグレーションによって実現できる、その他のサンプルユースケースです:
- Monitoringサービスのストレージ使用率メトリックからあがったアラームをきっかけに、Oracle Autonomous Databaseのストレージをスケールアップする
- Automatic Volume Healingを使い、あるブロックボリューム上の利用率がしきい値を越えたことをきっかけに追加ボリュームを作成し、アタッチすることでボリュームを拡張する。また、その新しいディスク容量の詳細について通知を発出する。
- サービスやファンクションにカスタムメッセージを発出しつつ、別のファンクションをトリガーする
始めてみよう
Oracle Cloud Infrastructure Notificationsを使っているなら、この新機能はコンソール、SDK、CLIおよびAPIを通じてサブスクリプションを作成するときに利用可能です。以下はいくつかのやり方のサンプルです。
コンソール:トピックへのサブスクリプションの作成
トピックにサブスクリプションを作成する際に、プロトコルタイプとしてFunctionを選んでください。
![Screenshot that shows the Create Subscription button on the topic details page in the console.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/7a20e1eef0cec02ed934c9db9615ac03/1_create_subscription_button.png)
![Screenshot that shows the Create Subscription dialog box with Function selected as the protocol.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/d9198c400b71ceed53afb1c0e3fa709b/2_select_function_create_subscription.png)
トリガーしたいファンクションとそのコンパートメントを選択します。
![Screenshot that shows the Create Subscription dialog box with values in the function compartment, function application, and function fields.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/64b7ffebee8b8af8ccf9de990b35fb2c/3_select_functions.png)
サブスクリプションが作成されると、コンソールに表示されます。
![Screenshot that shows the subscription details page on the console.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/338bf54f579bc8bd12fd188ea1e1c2e5/4_function_subscription_view.png)
コンソール:アラームの作成
コンソールのMonitoringのページから、Alarm Definitionsをクリックし、Create Alarmをクリック。
![Screenshot that shows the Create Alarm button on the alarm definitions page in the console.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/78dda7fcbc93527866f4a3f843451b8b/5_create_alarm.png)
アラームの必要情報を入力します。
![Screenshot that shows the Create Alarm dialog box with the Define alarm area in focus.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/53951a1de97f68c4fcc2fc8c695ad4d3/6_creating_alarm_definition.png)
Notificationsの欄では既存のトピックを選択するか、ここから新しくトピックを作成することもできます。
![Screenshot that shows the Create Alarm dialog box with the Notifications area in focus and the Create a topic link highlighted.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/19c31abd4033d319270e3d4f65243363/7_alarm_notification.png)
![Screenshot that shows the Create Alarm dialog box with the Notifications area in focus and the Create a new topic and subscription fields highlighted.](http://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/211f80a6-5f1b-4459-9268-9903fb8e93c1/Image/7eebe453fc5675248ea9dbf94a8f4db2/8_creating_alarm_function.png)
CLI
ファンクションのサブスクリプションの作成:
oci ons subscription create \
--compartment-id "<compartment-ocid>" \
--topic-id "<topic-ocid>" \
--protocol "ORACLE_FUNCTIONS" \
--subscription-endpoint "<function_ocid>"
Java SDK
ファンクションのサブスクリプションの作成:
subscription = client.createSubscription(CreateSubscriptionRequest.builder()
.createSubscriptionDetails(CreateSubscriptionDetails.builder()
.compartmentId(compartmentId)
.topicId(topicId)
.protocol("ORACLE_FUNCTIONS")
.endpoint(functionId)
.build())
.build()).getSubscription();
Terraform
Provider Configurationで以下のようにプロトコルを設定します。
variable "subscription_protocol" {
...
default = "ORACLE_FUNCTIONS"
...
...
}
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}"
}
REST API
ファンクションのサブスクリプションの作成:
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>"
}
課金について
Notificationsサービスからファンクションをトリガーするのに追加の料金は必要ありません。Oracle Functionsの課金についてはこちらの製品ページを確認ください。
より詳しい情報
この新機能のより詳しい情報や、Notificationsサービスについて詳しいことを知りたければ以下のリンクをたどってみてください。
- Notifications-Functions integration documentation
- Notifications-Functions developer walkthrough blog post
- Example: Automated VM resize scenario
- Example: E-Commerce application order processing system using Notifications and Functions
- Notifications documentation
- Notifications REST API reference
- Notifications CLI reference
- Notifications product page
- Notifications pricing