Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dario-vega/test-demo-code-editor
(todo) move to https://github.com/oracle-samples/oracle-functions-samples
https://github.com/dario-vega/test-demo-code-editor
Last synced: 1 day ago
JSON representation
(todo) move to https://github.com/oracle-samples/oracle-functions-samples
- Host: GitHub
- URL: https://github.com/dario-vega/test-demo-code-editor
- Owner: dario-vega
- Created: 2022-09-07T07:09:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-04T18:17:43.000Z (over 1 year ago)
- Last Synced: 2024-11-06T21:49:18.312Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Function that reads data using the OCI Node.js for Oracle NoSQL Database CS
This function uses Resource Principals to securely authorize a function to make
API calls to Oracle NoSQL Database. You can query tables in a compartmenthello-nosql
As you make your way through this tutorial, look out for this icon ![user input icon](https://github.com/oracle-samples/oracle-functions-samples/blob/master/images/userinput.png).
Whenever you see it, it's time for you to perform an action.## Prerequisites
1. Before you deploy this sample function, make sure you have run steps A, B
and C of the [Oracle Functions Quick Start Guide for Cloud Shell](https://docs.oracle.com/en-us/iaas/Content/Functions/Tasks/functionsquickstartcloudshell.htm)
* A - Set up your tenancy
* B - Create application
* C - Set up your Cloud Shell dev environment## List Applications
Assuming you have successfully completed the prerequisites, you should see your
application in the list of applications.```
fn ls apps
```## Create or Update your Dynamic Group
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).![user input icon](https://github.com/oracle-samples/oracle-functions-samples/blob/master/images/userinput.png)
When specifying the *Matching Rules*, we suggest matching all functions in a compartment with:
```
ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'}
```## Create or Update IAM Policies
Create a new policy that allows the dynamic group to `manage objects` in the functions related compartment.
![user input icon](https://github.com/oracle-samples/oracle-functions-samples/blob/master/images/userinput.png)
Your policy should look something like this:
```
Allow dynamic-group to manage nosql-family in compartment
```
e.g.
```
Allow dynamic-group demo-func-dyn-group to manage nosql-family in compartment demo-func-compartment
```
For more information on how to create policies, go [here](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm).## Review and customize the function
Review the following files in the current folder:
- [package.json](./package.json) specifies all the dependencies for your function
- [func.yaml](./func.yaml) that contains metadata about your function and declares properties
- [func.js](./func.js) which is the Node.js function## Deploy the function
In Cloud Shell, run the `fn deploy` command to build the function and its dependencies as a Docker image,
push the image to the specified Docker registry, and deploy the function to Oracle Functions
in the application created earlier:![user input icon](https://github.com/oracle-samples/oracle-functions-samples/blob/master/images/userinput.png)
```
COMP_ID=""
fn config app NOSQL_COMPARTMENT_ID $COMP_ID
fn config app NOSQL_REGION $OCI_REGION
fn config app FN_API_KEY```
e.g.
```
COMP_ID=`oci iam compartment list --all --name demonosql | jq -r '."data"[].id'`
fn config app myapp NOSQL_COMPARTMENT_ID $COMP_ID
fn config app myapp NOSQL_REGION $OCI_REGION
fn config app myapp FN_API_KEY "MY_FN_API_KEY_VALUE"
``````
fn -v deploy --app
```
e.g.
```
fn -v deploy --app myapp
```## Create Nosql Tables
![user input icon](https://github.com/oracle-samples/oracle-functions-samples/blob/master/images/userinput.png)
````
COMP_ID=`oci iam compartment list --all --name demonosql | jq -r '."data"[].id'`DDL_TABLE="CREATE TABLE IF NOT EXISTS Tutorial (id LONG GENERATED BY DEFAULT AS IDENTITY (NO CYCLE), kv_json_ JSON, PRIMARY KEY( id ))"
echo $DDL_TABLEoci nosql table create --compartment-id "$COMP_ID" \
--name Tutorial --ddl-statement "$DDL_TABLE" \
--table-limits="{\"maxReadUnits\": 50, \"maxStorageInGBs\": 25, \"maxWriteUnits\": 50 }" \
--wait-for-state SUCCEEDED --wait-for-state FAILEDoci nosql row update --compartment-id "$COMP_ID" --table-name-or-id Tutorial \
--value '{"kv_json_": { "author": { "name": "Dario VEGA"}, "title": "Oracle Functions Samples with NOSQL DB"}}'
````## Test
![user input icon](https://github.com/oracle-samples/oracle-functions-samples/blob/master/images/userinput.png)
```
echo -n | fn invoke
```
e.g.
```
echo '{"tableName":"Tutorial"}' | fn invoke myapp hello-nosql | jq
```You should see the following JSON document appear in the terminal.
```
[
{
"id": 1,
"kv_json_": {
"author": {
"name": "Dario VEGA"
},
"title": "Oracle Functions Samples with NOSQL DB"
}
}
]
```## Clean Up
```
oci nosql table delete --compartment-id "$COMP_ID" --table-name-or-id Tutorial
```