12. Functions Creation Steps - CloudDarsh/OracleCloud GitHub Wiki

STEPS TO CREATE FUNCTIONS

Step1: Create Functions

dnerw (1)

Untitled (2400 x 1080 px) (1)

Step2: We can use Cloud shell option to proceed further

Untitled design (17)

Step3: Open the cloud shell

YouTube Thumbnail (32)

Step4: Check the context (*) denotes which region context is pointing. Validate If it matches your current region

$ fn list context

Switch to right context $ fn use context eu-frankfurt-1

YouTube Thumbnail (37)

Step5: Update the context with the function's compartment ID

$ fn update context oracle.compartment-id ocid1.compartment.oc1..aaaaaaaape26buh5zkbujozgyrlecuplate5qvmllg3ym3ajotrz4q2q6yzq

YouTube Thumbnail (38)

Step6: Provide a unique repository name prefix to distinguish your function images from other people’s. For example, with 'jdoe' as the prefix, the image path for a 'hello' function image is '.ocir.io//jdoe/hello:0.0.1'

$ fn update context registry fra.ocir.io/ctspaas072018/[repo-name-prefix]

YouTube Thumbnail (39)

Step7: Generate an Auth token

This step can be taken from Auth token document

[IMPORTANT] Step8: Update the context with oracle image compartment id.

It configures the fn project context with the ocid of the compartment for repository to and from which our oracle function will push and pull the images.

$ fn update context oracle.image-compartment-id <ocid_of_cpompartment_id>

YouTube Thumbnail (40)

If you don’t give this details it will try to push into root compartment

Step8:Login to the registry

$ docker login -u ‘xxxx/[email protected]' fra.ocir.io Password: [PASS THE AUTH TOKEN GENERATED IN STEP7]

YouTube Thumbnail (41)

Step9: Generate a 'hello-world' boilerplate function

$ fn init --runtime java hello-java

YouTube Thumbnail (42)

Step 10: Deploy your function

List the application, It display’s the application created in OCI.

$ fn list apps NAME ID Helloworld-app ocid1.fnapp.oc1.eu-frankfurt-1.XXXXXXXXXXXXX

Let’s Deploy the function.

$ fn -v deploy --app Helloworld-app

YouTube Thumbnail (43)

YouTube Thumbnail (44)

image

STEP 11: Let's invoke the function

$ fn invoke Helloworld-app hello-java Hello, world!

$ echo -n 'xyz' | fn invoke Helloworld-app hello-java Hello, xzy!

YouTube Thumbnail (45)

⚠️ **GitHub.com Fallback** ⚠️