Skip to main content

Command Palette

Search for a command to run...

Oracle Functions and .NET - Getting Started Part 2

Updated
5 min read

In Part 1 of this blog, we discussed setting up the OCI account so that you were ready to publish your first OCI function. In this section, we will set up the account so that you can actually write code and publish a function.

In Part 2 of the blog post, we are going to get the local development environment set up to write our first function.

Prerequisites

To progress any further, you must have access to development tools on your dev machine. I’m not going to go into how to install those tools here, but here are some of the tools that you will need.

  • Docker / Docker Desktop

  • IDE of choice, in my case VS Code

  • Language SDKs ie Node, Python, .NET, etc

  • Nano - to edit the configuration files

  • Curl

Languages supported by OCI Functions are listed here.

Strictly speaking, the IDE is not required as we will not be editing function code. However, it’s always a good idea to have your IDE on hand to explore some of the boilerplate files that get generated.

API Keys

In order to be able to invoke OCI APIs you will need to have an API key. This key is a cryptographic key pair that allows you to call the OCI APIs in your account.

From the OCI console, open the Hamburger menu, select Identity and Security, and then click Domains.

DOmains are collections of users. Every OCI tenancy has a default domain with the root user account. You can create additional users, groups, and accounts in your default domain. You can also create multiple different domains for different use cases. However, that is a more advanced feature than we are dealing with here.

Because this is a first “Getting Started” blog, I am going to assume that you are either using the default user account that was created with your tenancy or another account that is a member of the administrator’s group. In a future blog, I will cover how to scope things down so that you don’t have to be an administrator.

Your account will have a default domain that was created when your account was created. Assuming that your user account in the OCI Tenancy is in the default Domain, click Default. (OCI can support multiple Domains in your tenancy. This is a more advanced concept and I am assuming that this is not the case for your environment.)

Select Users from the left hand navigation menu, and then select your user account.

From your user account, select API Keys, and then “Add API key.”

From the Add API key, you can use several options to create API keys to use.

For this project, I will download the public and private keys and store them locally. Note that this is the only opportunity to download the private key, so keep it safe. If you lose it, you will have to create a new key pair.

Store the files in your user profile in a sub-directory called “.oci.” Once you have the files on your local drive and click Add, you will be presented with a screen that shows you how to set up your OCI SDK configuration file.

Copy the data and create a file called “config” in your .oci folder alongside your key files. Note that you need to update the file to match the location of your private key file.

Once you have saved the config file, make sure that your private key is only readable by you.

chmod go-rwx ~/.oci/<private-key-file-name>.pem

Create an Auth token.

Back in the OCI console, you will also need to create an Auth token. On your user account page, click “Auth tokens” and then “Generate token.” This token will be used to interact with the OCI Image repository that you created in order to store your function images.

Provide a name for the token that you will remember.

Then click “Generate token” at the bottom of the page.

As the page indicates, you need to copy this town and store it somewhere you will have access to later. If you lose this token, you must delete it and create a new one, as this is a one-time download. This token is used like a password when you gign into the image repository with Docker.

I’ve saved the token in my Documents folder for easy access.

Install the Fn Command line tool.

Next, you can download and install the Fn Command-like tool. This will be used to publish your functions once you have written them. Use the following command line to download and install the Fn project command line.

curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

Set up the Fn content with the following commands. This creates a configuration called Oracle that will be set up and configured to use the OCI function service.

fn create context Oracle --provider oracle
fn use context Oracle

From the OCI console, we need to obtain the OCID for the compartment that you re going to use for publishing your functions. In the OCI console, from the hamburger menu, select “Identity and Security” and “Compartments.”

Hover your mouse over the OCID column for the compartment that you are using, and select Copy.

Back at the command line, enter the following command:

fn update context oracle.compartment-id <<compartment-ocid>>

Fill in the compartment OCID with the value you copied from the console.

Enter the following command to configure the endpoint you will interact with. You can find the list of API endpoints here.

fn update context api-url https://functions.<<Region Key>>.oci.oraclecloud.com

Enter the following command to specify the image repository you configured in part 1. The region key will be the same region key used above. The namespace is a value that you retrieved after the creation of the repository. And RepositoryName will be the name that you gave when you created your repository.

fn update context registry ocir.<<RegionKey>>.oci.oraclecloud.com/<<NameSpace>>/<<RepositoryName>>

The final update to your environment will be to let the Fn command line know how to connect the container registry that you created to the compartment that it resides in. Use the following command:

fn update context oracle.image-compartment-id <<compartment-ocid>>

The compartment OCID will be the same as the one used earlier.

With all of this completed, your development environment is ready to go!

In part 3 of this blog series, we will create a function. Don’t worry; all the work you did in the first two blog posts is a one-off setup. You won’t have to do this again anytime soon.

More from this blog

B

Basement Programmer Blog

36 posts

.NET Developer working out of my basement, helping developers to move into the cloud.