Above diagram describes the architecture of oracle function for our use case.
This OCI Function that pulls objects from a bucket and pushes them to a remote host and the deletes the object from the bucket.
This function uses Resource Principals to securely authorize a function to make API calls to OCI services using the OCI Python SDK.
The function calls the following OCI Python SDK classes:
Resource Principals Signer to authenticate.
Object Storage Client to interact with Object Storage.
To follow along make sure you have your tenancy created in OCI and docker installed.
Create OCI Group and OCI user, Assign the user to this group. Give the following privileges via policy to group
Allow group oci_group to manage repos in tenancy
allow group oci_group to manage objects in tenancy
allow group oci_group to use repos in tenancy
allow group oci_group to read repos in tenancy
allow group oci_group to use keys in compartment sandbox
allow group oci_group to read objectstorage-namespaces in compartment sandbox
Allow group oci_group to manage all-resources in tenancy
Also generate an AUTH token for us to use the user to login via docker cli
ALL {resource.type = 'fnfunc', resource.compartment.id = 'ocid1.tenancy.oc1...'}Allow service objectstorage-us-ashburn-1 to manage object-family in compartment sandbox
Allow dynamic-group function-dynamic-group to manage objects in compartment sandbox
Allow dynamic-group function-dynamic-group to manage buckets in compartment sandbox
Allow dynamic-group function-dynamic-group to manage secret-family in tenancycreate an API key and copy private/public key on to your system.
create a directory as .oci in your home directory and then put the information received while creating api key into a file called config.
fn command uses this information to connect to OCI and upload container image and deploy functions
[DEFAULT]
user=ocid1.user.oc1..<redacted>
fingerprint=15:0e:02:ea:4b:27:c9:b8:7c:<redacted>
tenancy=ocid1.tenancy.oc1..<redacted>
region=us-ashburn-1
compartment-id=ocid1.compartment.oc1..<redacted>
key_file=/home/username/.oci/<redacted>.pemdocker login us-ashburn-1.ocir.io -u '<namespace>/<username>' -p '<auth token>'curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | shfn versionfn create context ocir-context --provider oracle
fn update context registry us-ashburn-1.ocir.io/<namespace>/download_and_transfer
fn update context oracle.compartment-id <tenancy_ocid>
fn update context api-url https://functions.us-ashburn-1.oraclecloud.comIn my case i've used us-ashburn-1 as my region key. Also make sure that the region key in both docker login and fn context is same. Fn uses docker login to push and pull images from OCI registry
(dntv4) ubuntu@dockervm:$ fn use context ocir-context
(dntv4) ubuntu@dockervm:$ fn list context
CURRENT NAME PROVIDER API URL REGISTRY
default default http://localhost:8080 iad.ocir.io/<namespace>/dnt
* ocir-context oracle https://functions.us-ashburn-1.oraclecloud.com us-ashburn-1.ocir.io/<namespace>/download_and_transferThis can be done via OCI Dashboard
To deploy this project we will create an application
fn create app download_and_transfer --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.iad...."]'If you want to add more than one subnets or include vcn you can use following command
fn create app download_and_transfer --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.iad.<redacted>","ocid1.subnet.oc1.iad.<redacted>"]' --annotation oracle.com/oci/vcnId='["ocid1.vcn.oc1.iad.<redacted>"]'Build and push the image to OCI registry
fn --verbose deploy --app download_and_transferYou may have to add network security group to allow docker container to access the remote host.
You can do this as suggested in below screenshot , This configuration is in application
Update the SECRET_OCID configuration of function with the ocid of secret created earlier.
To test the build , Enable emit events of a bucket.
At this point you can upload the objects to the bucket which should invoke the function and the function should pull the objects from the bucket transfers it to remote host and deletes the object from the bucket.





