|
| 1 | +# Function that lists objects from a bucket in Object Storage using the OCI Dotnet SDK |
| 2 | + |
| 3 | +This function uses Resource Principals to securely authorize a function to make |
| 4 | +API calls to OCI services using the [OCI Dotnet SDK](https://docs.oracle.com/en-us/iaas/tools/dotnet/latest/api/index.html). |
| 5 | +It returns a list of objects from a given bucket in Object Storage. |
| 6 | + |
| 7 | +The function calls the following OCI Dotnet SDK classes: |
| 8 | +* [Resource Principals](https://docs.oracle.com/en-us/iaas/tools/dotnet/latest/api/Oci.Common.Auth.ResourcePrincipalAuthenticationDetailsProvider.html) to authenticate |
| 9 | +* [Identity Client](https://docs.oracle.com/en-us/iaas/tools/dotnet/latest/api/Oci.IdentityService.IdentityClient.html) to interact with Identity and Access Management |
| 10 | + |
| 11 | +As you make your way through this tutorial, look out for this icon . |
| 12 | +Whenever you see it, it's time for you to perform an action. |
| 13 | + |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +1. Before you deploy this sample function, make sure you have run steps A, B |
| 18 | +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) |
| 19 | + * A - Set up your tenancy |
| 20 | + * B - Create application |
| 21 | + * C - Set up your Cloud Shell dev environment |
| 22 | + |
| 23 | +2. Have your Oracle Object Storage Namespace available. This can be found by |
| 24 | +logging into your [cloud account](https://console.us-ashburn-1.oraclecloud.com/), |
| 25 | +under your user profile, click on your Tenancy. Your Object Storage Namespace |
| 26 | +is shown there. |
| 27 | + |
| 28 | + |
| 29 | +## List Applications |
| 30 | + |
| 31 | +Assuming you have successfully completed the prerequisites, you should see your |
| 32 | +application in the list of applications. |
| 33 | + |
| 34 | +``` |
| 35 | +fn ls apps |
| 36 | +``` |
| 37 | + |
| 38 | + |
| 39 | +## Create or Update your Dynamic Group |
| 40 | + |
| 41 | +In order to use other OCI Services, your function must be part of a dynamic |
| 42 | +group. For information on how to create a dynamic group, refer to the |
| 43 | +[documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Tasks/managingdynamicgroups.htm#To). |
| 44 | + |
| 45 | +When specifying the *Matching Rules*, we suggest matching all functions in a compartment with: |
| 46 | + |
| 47 | +``` |
| 48 | +ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'} |
| 49 | +``` |
| 50 | + |
| 51 | + |
| 52 | +## Create or Update IAM Policies |
| 53 | + |
| 54 | +Create a new policy that allows the dynamic group to `inspect objects` in |
| 55 | +the functions related compartment. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +Your policy should look something like this: |
| 60 | +``` |
| 61 | +Allow dynamic-group <dynamic-group-name> to inspect objects in compartment <compartment-name> |
| 62 | +``` |
| 63 | +e.g. |
| 64 | +``` |
| 65 | +Allow dynamic-group demo-func-dyn-group to inspect objects in compartment demo-func-compartment |
| 66 | +``` |
| 67 | +For more information on how to create policies, go [here](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm). |
| 68 | + |
| 69 | + |
| 70 | +## Review and customize the function |
| 71 | + |
| 72 | +Review the following files in the current folder: |
| 73 | + |
| 74 | +- [ListObjects.csproj](./ListObjects.csproj) specifies all the dependencies for your function |
| 75 | +- [func.yaml](./func.yaml) that contains metadata about your function and declares properties |
| 76 | +- [ListObjects.cs](./ListObjects.cs) which is your actual Dotnet function |
| 77 | + |
| 78 | +The name of your function *oci-objectstorage-list-objects-dotnet* is specified in [func.yaml](./func.yaml). |
| 79 | + |
| 80 | + |
| 81 | +## Deploy the function |
| 82 | + |
| 83 | +In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image, |
| 84 | +push the image to the specified Docker registry, and deploy the function to Oracle Functions |
| 85 | +in the application created earlier: |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +``` |
| 90 | +fn -v deploy --app <app-name> |
| 91 | +``` |
| 92 | +e.g. |
| 93 | +``` |
| 94 | +fn -v deploy --app myapp |
| 95 | +``` |
| 96 | + |
| 97 | + |
| 98 | +## Test |
| 99 | + |
| 100 | + |
| 101 | +``` |
| 102 | +echo -n <JSON-object> | fn invoke <app-name> <function-name> |
| 103 | +``` |
| 104 | +e.g. |
| 105 | +``` |
| 106 | +echo -n '{"bucketName": "<bucket-name>","namespaceName":"<bucket-namespace>"}' | fn invoke myapp oci-objectstorage-list-objects-dotnet |
| 107 | +``` |
| 108 | +You should see a list of objects from the bucket in the terminal. |
| 109 | + |
| 110 | + |
| 111 | +## Monitoring Functions |
| 112 | + |
| 113 | +Learn how to configure basic observability for your function using metrics, alarms and email alerts: |
| 114 | +* [Basic Guidance for Monitoring your Functions](../basic-observability/functions.md) |
| 115 | + |
0 commit comments