|
| 1 | +# Simple Object Upload Function |
| 2 | +This function is used to simply demonstrate connectivity with SaaS applications through OIC. It takes POST request parameters and puts data into a csv file that is uploaded onto Object Storage. |
| 3 | + |
| 4 | +As you make your way through this tutorial, look out for this icon . |
| 5 | +Whenever you see it, it's time for you to perform an action. |
| 6 | + |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | +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) |
| 10 | +* A - Set up your tenancy |
| 11 | +* B - Create application |
| 12 | +* C - Set up your Cloud Shell dev environment |
| 13 | + |
| 14 | + |
| 15 | +## List Applications |
| 16 | +Assuming your have successfully completed the prerequisites, you should see your |
| 17 | +application in the list of applications. |
| 18 | +``` |
| 19 | +fn ls apps |
| 20 | +``` |
| 21 | + |
| 22 | + |
| 23 | +## Create or Update your Dynamic Group |
| 24 | +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). |
| 25 | + |
| 26 | +When specifying the *Matching Rules*, we suggest matching all functions in a compartment with: |
| 27 | +``` |
| 28 | +ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'} |
| 29 | +``` |
| 30 | +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. |
| 31 | + |
| 32 | + |
| 33 | +## Create or Update IAM Policies |
| 34 | +Create a new policy that allows the dynamic group to manage compute instances. We will grant `inspect/use/manage` access to `xxx` in the compartment. |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +Your policy should look something like this: |
| 39 | +``` |
| 40 | +Allow dynamic-group <dynamic-group-name> to xxx XXX in compartment <compartment-name> |
| 41 | +``` |
| 42 | + |
| 43 | +For more information on how to create policies, check the [documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm). |
| 44 | + |
| 45 | + |
| 46 | +## Review and customize the function |
| 47 | +Review the following files in the current folder: |
| 48 | +* the code of the function, [func.py](./func.py) |
| 49 | +* its dependencies, [requirements.txt](./requirements.txt) |
| 50 | +* the function metadata, [func.yaml](./func.yaml) |
| 51 | + |
| 52 | + |
| 53 | +## Deploy the function |
| 54 | +In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image, |
| 55 | +push the image to OCIR, and deploy the function to Oracle Functions in your application. |
| 56 | + |
| 57 | + |
| 58 | +``` |
| 59 | +fn -v deploy --app <app-name> |
| 60 | +``` |
| 61 | + |
| 62 | +## Set the function configuration values |
| 63 | +The function requires the following configuration values to be set: |
| 64 | +- OCI_NAMESPACE |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +Use the *fn CLI* to set the config value: |
| 69 | +``` |
| 70 | +fn config function <app-name> <function-name> OCI_NAMESPACE <NAMESPACE> |
| 71 | +``` |
| 72 | +e.g. |
| 73 | +``` |
| 74 | +fn config function myapp OCI_NAMESPACE mynamespace |
| 75 | +``` |
| 76 | + |
| 77 | +## Expected Function Input |
| 78 | +```bash |
| 79 | +# the function expects the following payload: |
| 80 | +{ |
| 81 | + "firstname": "", |
| 82 | + "lastname": "", |
| 83 | + "workemail": "", |
| 84 | + "hiredate": "", |
| 85 | + "effectivestartdate": "", |
| 86 | + "personid": "" |
| 87 | +} |
| 88 | +``` |
0 commit comments