This function starts, stops and return the status of an OCI Compute instance.
As you make your way through this tutorial, look out for this icon . Whenever you see it, it's time for you to perform an action.
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
- A - Set up your tenancy
- B - Create application
- C - Set up your Cloud Shell dev environment
Assuming you have successfully completed the prerequisites, you should see your application in the list of applications.
fn ls apps
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.
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 a new policy that allows the dynamic group to manage compute instances.
We will grant manage
access to instances
in the compartment.
Your policy should look something like this:
Allow dynamic-group <dynamic-group-name> to manage instances in compartment <compartment-name>
e.g.
Allow dynamic-group demo-func-dyn-group to manage instances in compartment demo-func-compartment
For more information on how to create policies, go here.
Review the following files in the current folder:
- the code of the function, func.py
- its dependencies, requirements.txt
- the function metadata, func.yaml
fn -v deploy --app <app-name>
e.g.
fn -v deploy --app myapp
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:
echo '{"command":"<command>", "instance_ocid":"<instance-ocid>"}' | fn invoke <app-name> <function-name>
e.g. To stop an instance:
echo '{"command":"stop", "instance_ocid":"ocid1.fnfunc.oc1.iad.aaaaaxxxxx"}' | fn invoke myapp oci-compute-control-python
The supported values for command
are "status", "start" and "stop".
You should see the status of the instance returned by the function.
Learn how to configure basic observability for your function using metrics, alarms and email alerts: