|
| 1 | +# Function that logs the details of a Cloud event |
| 2 | + |
| 3 | +This function logs the details of a Cloud event. |
| 4 | + |
| 5 | +As you make your way through this tutorial, look out for this icon . |
| 6 | +Whenever you see it, it's time for you to perform an action. |
| 7 | + |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | +Before you deploy this sample function, make sure you have run step A, B and C of the [Oracle Functions Quick Start Guide for Cloud Shell](https://www.oracle.com/webfolder/technetwork/tutorials/infographics/oci_functions_cloudshell_quickview/functions_quickview_top/functions_quickview/index.html) |
| 11 | +* A - Set up your tenancy |
| 12 | +* B - Create application |
| 13 | +* C - Set up your Cloud Shell dev environment |
| 14 | + |
| 15 | + |
| 16 | +## List Applications |
| 17 | +Assuming your have successfully completed the prerequisites, you should see your |
| 18 | +application in the list of applications. |
| 19 | +``` |
| 20 | +fn ls apps |
| 21 | +``` |
| 22 | + |
| 23 | + |
| 24 | +## Create or Update your Dynamic Group |
| 25 | +In order to use other OCI Services, your function must be part of a dynamic group. For information on how to create a dynamic group, refer to the [documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingdynamicgroups.htm#To). |
| 26 | + |
| 27 | +When specifying the *Matching Rules*, we suggest matching all functions in a compartment with: |
| 28 | +``` |
| 29 | +ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'} |
| 30 | +``` |
| 31 | +Please check the [Accessing Other Oracle Cloud Infrastructure Resources from Running Functions](https://docs.cloud.oracle.com/en-us/iaas/Content/Functions/Tasks/functionsaccessingociresources.htm) for other *Matching Rules* options. |
| 32 | + |
| 33 | + |
| 34 | +## Review and customize your function |
| 35 | +Review the following files in the current folder: |
| 36 | +* the code of the function, [LogEvents.cs](./LogEvents.cs) |
| 37 | +* its dependencies, [LogEvents.csproj](./LogEvents.csproj) |
| 38 | +* the function metadata, [func.yaml](./func.yaml) |
| 39 | + |
| 40 | + |
| 41 | +## Deploy the function |
| 42 | +In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image, |
| 43 | +push the image to OCIR, and deploy the function to Oracle Functions in your application. |
| 44 | + |
| 45 | + |
| 46 | +``` |
| 47 | +fn -v deploy --app <app-name> |
| 48 | +``` |
| 49 | + |
| 50 | + |
| 51 | +## Create the Cloud Event rule |
| 52 | +Create a Cloud Event rule on the console navigating to Application Integration > Event Service. Click *Create Rule*. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +Assign a display name and a description, customize the Rule Conditions or leave them empty to match all events. In the *Actions* section, set the *Action type* as "Functions", select your *Function Compartment*, your *Function Application*, and your *Function ID*. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +## Test |
| 61 | +Go to the logs, you should see events from your compartment. You can create some resource such as an Object Storage bucket to generate an event. |
| 62 | +For example: |
| 63 | +```json |
| 64 | +event type: com.oraclecloud.objectstorage.createbucket |
| 65 | +compartment name: greg-verstraeten |
| 66 | +Full Cloud event json data: |
| 67 | +{ |
| 68 | + "eventType": "com.oraclecloud.objectstorage.createbucket", |
| 69 | + "cloudEventsVersion": "0.1", |
| 70 | + "eventTypeVersion": "2.0", |
| 71 | + "source": "ObjectStorage", |
| 72 | + "eventTime": "2019-12-12T22:25:08.502Z", |
| 73 | + "contentType": "application/json", |
| 74 | + "data": { |
| 75 | + "compartmentId": "ocid1.compartment.oc1..aaaaaaaal66tw5k262fsjsrgdqan5cbbfxvoydbhxx5hijth2h3qlbwmtdlq", |
| 76 | + "compartmentName": "greg-verstraeten", |
| 77 | + "resourceName": "bucket-20191212-1425", |
| 78 | + "resourceId": "/n/devrel/b/", |
| 79 | + "availabilityDomain": "PHX-AD-2", |
| 80 | + "additionalDetails": { |
| 81 | + "bucketName": "bucket-20191212-1425", |
| 82 | + "publicAccessType": "NoPublicAccess", |
| 83 | + "namespace": "devrel", |
| 84 | + "eTag": "47b12898-1925-449a-a761-7d1db57f0695" |
| 85 | + } |
| 86 | + }, |
| 87 | + "eventID": "fca0653f-85c5-9466-8812-001c51d338a4", |
| 88 | + "extensions": { |
| 89 | + "compartmentId": "ocid1.compartment.oc1..aaaaaaaal66tw5k262fsjsrgdqan5cbbfxvoydbhxx5hijth2h3qlbwmtdlq" |
| 90 | + } |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | +## Monitoring Functions |
| 96 | + |
| 97 | +Learn how to configure basic observability for your function using metrics, alarms and email alerts: |
| 98 | +* [Basic Guidance for Monitoring your Functions](../basic-observability/functions.md) |
| 99 | + |
0 commit comments