{OCI イベント} イベントの開始

https://docs.oracle.com/ja-jp/iaas/Content/Events/Concepts/eventsgetstarted.htm


前提: VCN作成済

 

-- 1. トピック作成


oci ons topic create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--name topic01 

 


oci ons topic list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--all 

 


-- 2. サブスクリプション作成

oci ons subscription create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--protocol EMAIL \
--subscription-endpoint hoge@example.com \
--topic-id ocid1.onstopic.oc1.iad.000000000000000000000000000000000000000000000000000000000000 


oci ons subscription list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 


メールがくるのでsubscribeする


-- 3. ルール作成

cat <<-'EOF' > rule01.json

{
  "actions": [
      {
        "actionType": "ONS",
        "description": "rule01",
        "isEnabled": true,
        "topicId": "ocid1.onstopic.oc1.iad.000000000000000000000000000000000000000000000000000000000000"
      }
  ]
}

EOF

 

oci events rule create --generate-full-command-json-input


oci events rule create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--display-name rule01 \
--actions file://rule01.json \
--condition "{\"eventType\":[\"com.oraclecloud.objectstorage.createbucket\"]}" \
--is-enabled true

 

oci events rule list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 

 

-- 4. 動作確認


oci os bucket create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--name bucket01 \
--auto-tiering Disabled \
--object-events-enabled true \
--public-access-type NoPublicAccess \
--storage-tier Standard \
--versioning Disabled

oci os bucket create \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--name bucket02 \
--auto-tiering Disabled \
--object-events-enabled false \
--public-access-type NoPublicAccess \
--storage-tier Standard \
--versioning Disabled

oci os bucket list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \


bucket01、bucket01について
メールが来ることを確認

 

-- 5. クリーンアップ

-- バケット削除

oci os bucket list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 


oci os bucket delete \
--name bucket01 \
--empty \
--force

oci os bucket delete \
--name bucket02 \
--empty \
--force


-- ルール削除

 

oci events rule list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 

oci events rule delete \
--rule-id ocid1.eventrule.oc1.iad.000000000000000000000000000000000000000000000000000000000000 \
--force 

 

-- サブスクリプション削除

oci ons subscription list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 


oci ons subscription delete \
--subscription-id ocid1.onssubscription.oc1.iad.000000000000000000000000000000000000000000000000000000000000 \
--force 

 

-- トピック削除


oci ons topic list \
--compartment-id ocid1.compartment.oc1..000000000000000000000000000000000000000000000000000000000000 \
--all 

oci ons topic delete \
--topic-id ocid1.onstopic.oc1.iad.000000000000000000000000000000000000000000000000000000000000 \
--force 


削除されるまで時間がかかる