# Oracle Functions and .NET - Getting Started Part 2

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](https://docs.oracle.com/en-us/iaas/Content/Functions/Tasks/languagessupportedbyfunctions.htm#functionssupportedlanguageversions_topic_Language_versions_supported_by_FDKs).

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733512250537/49e37ea1-8c1d-4dd2-923e-1a87d5beada7.png align="center")

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.)*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733512381883/a1a4357e-ed24-4e86-acf3-fac08c3f6fdd.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733512575699/279f1d3a-3421-41b8-9da4-5da61eaac67e.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733512645222/55687857-48c1-4325-9647-a478dd7895a8.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733512783041/2830b07c-205f-44e6-828d-4de967e72df1.png align="center")

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733513512302/bdff0bd9-4c15-46b3-a3d9-f562522b7e9b.png align="center")

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733513725453/68a1bc89-766c-43c1-ad5a-d74f6da5f51a.png align="center")

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

```bash
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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733572406726/f9d42a2e-d95c-4395-91c5-49c331147083.png align="center")

Provide a name for the token that you will remember.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733572440162/4fcfd36c-d4d8-41d6-a10a-3fdf80c8ec68.png align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733572500017/a3a81e9a-8212-4078-ab49-9fd18079c5f5.png align="center")

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.

```bash
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.

```bash
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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1733514610751/6cd3d439-d90d-4952-ab32-ce5adac0ea93.png align="center")

Back at the command line, enter the following command:

```bash
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](https://docs.oracle.com/en-us/iaas/api/#/en/functions/20181201/).

```bash
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.

```bash
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:

```bash
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.
