[MUSIC] Hello and welcome to this demo on functions quick start on cloud shell. I am Mahendra Mayra and I am a senior training lead and evangelist at Oracle University. We will be breaking this demo into four steps. As part of the first step, you will have to set up your 10ancy While setting up your 10ancy. You must ensure that you have suitable users and groups. You must also ensure that you have right compartments, visions and subnets. And finally you must create policy for group and service. So let's switch to O C. A console and see all of these in action. Alright, so I've logged in into the control as tenancy administrator. Let me take you to the users and groups and show you the users and groups which have already created for this demonstration. I'll click on the hamburger menu, go to the identity and security service, click on domains and select the default domain. If you see there is a users tab over here and there's a group stab in my default identity domain. If I select the users tab as you can see there are two users Mahi Mera and the other one is the tendency administrator. So we'll be using Mahi Mera. User in order to work with the function. Let me take you to the groups section. As you can see I've already created a group called function underscore ad min. And the use of this group is to bundle all the users together who work with the c function service. So if I click on this group, you will see that Mahi Mera is a user who has already added to this group. Alright now let me show you the compartment that I have created to work with, the function that quickly on the hamburger menu. Go to identity and security and click on compartments as you can see there's a compartment called functions underscore demo that is already created and we'll be creating our function within this compartment now for the user and the group that we have created to work with the function and the compartment where all the function resources will be created. We must write policies for both the groups as well as the service. Let me take you to the policies quick on the hamburger menu, go to identity and security and click on policies. Let me select the route compartment. As you can see I have already written policies under a policy name, functions under school policy. If I open it these are the list of policy templates that you can use in order to work with the functions. The use of policies totally depends upon the use case that you are following to create those functions. You can refer these policy templates from the Oc official documentation as part of step two for this demo we will be creating our first application in order to create application, we will be logging into the console and we will be logging in as the normal user that is Mahi Mera in order to work with the function. So let's hop onto the console So as you can see amid the clouds. Sign in page where the cloud account selected as oc developer training, the are NT domain is default and the user is Mahi Mera. So let me quickly click on sign in now to create our first application in the navigation menu, I will select the developers services, I'll select the applications under the function service, make sure that you select the right compartment from the compartment section. In our case, its function underscore demo. So I'll select functions underscore demo and click on create applications button to start creating your first application. Give your application a suitable name. So I have given my application the name. Hello World hyphen app. So now you need to select the V C N. And the subnets in which you wish to run your functions. In our case I've already created a V C N call function underscore demo underscore vision so it's auto selected within my compartment function underscore demo and from the subnets section I can select if I wish to load the function in a private subnets or within a public subnet. Make a note that a public subnets requires an internet gateway in the V C N. And the private subnets requires a service gateway in the V C N. Let me go ahead and select the public subnets. I leave the tagging options as blank and click on create so as you can see our application Hello world hyphen app has been created. So as this demo is about working with functions using cloud Shell. In the third step we will be setting up our cloud shell dev environment where we will be setting up the FN project context. We will be generating an authentication token and then using the authentication token, we will belonging into the registry which is our oracle cloud infrastructure registry, also popularly known as oc container registry. So let's jump back to the city council and see these steps in action. Alright, so in the step two, we created an application called Hello World hyphen app. Now, as you can see in the resources section, we have this getting started page where we can use the cloud Shell setup in order to access r C function or we can use a local setup. If a developer is comfortable working with our development machine that he owns for this demo, we will be going ahead with cloud Shell. So you can simply follow the steps given in the getting started page in order to launch your first Hello World application. So as I said, we need to launch the cloud shell in order to configure the FN projects. So let's click on the launch Cloud Shell. Either you can use this button to launch the cloud Shell or you can invoke the cloud shell from the menu bar technically con the launch cloud Shell Burton. And as you can see it's creating the cloud shell machine for us. Alright, so my cloud shell is up and running. Let me maximize the cloud shell. So the first command that will be running to set up the FN project cli context is the F enlace context command. What this command does is it helps us to find the name of pre created FN project context for the current region in which we wish to create the application so upon hitting enter. So if you see the output of the command, I see that there are two contexts. One is the default and another is the region where I basically want this function to be created. So I basically need to switch the context from the default to a p. Hyphen Mumbai hyphen man region for that. I'll be using the FN news context command followed by the region name. Alright, so there is the command FN news context space, the region name which is my current region. Let me enter and now the context has changed to a p hyphen Mumbai hyphen man. To cross check. You can use the f endless context command and see that the selection has changed from default to a p hyphen Mumbai hyphen man which is the region where I wish to create this function. Now the next thing is to configure the FN project context with the side of the current compartment that will own the deployed function in our case. The compartment is functions underscore demo. So this is the command which is used to set up the context to the side of the compartment. An update context or kill dot compartment hyphen id space the side of the compartment where you wish to create the function resources. So this compartment ID. Over here is the compartment idea of functions underscore demo that we had created earlier. Let me go ahead and hit enter and as you can see the current context is updated for the compartment. Now the next step is to configure the FN project context with the oracle cloud infrastructure registry address in the current region and tenancy that we want to use with the oracle function. So as you can see the command is fn update context registry followed by the registry address. So as you can see the registry address is the region key dot ocr dot io where the region key for ap Mumbai is B and it is less separated by the tenancy name space and slash separated by a repo name prefix. You can give any customized name as per your use case. So let me go ahead and click enter as you can see the current registry context has been updated. Now as part of the next step we need to generate an authentication token. So let me go ahead and click on the profile menu and go to my profile. Let me minimize the cloud shell. Now on the my profile page you can see under the resources section there is an art tokens option technically con are tokens and generate an auth token for this particular. Use case selectively congested token. Give it a valid name or description and click on generate token. So the token has been generated. You must ensure that you copy this token and save it somewhere. So let me copy the token and save it. Let's close this window and go back to our functions. Let me go to the hamburger menu. Click on developer services. Go back to applications, click on my application. Let's maximize the cloud shell. And the next step is to login into the OC. Registry using the authentication token. So the command is docker login hyphen you followed by the user name which is the tendency name space like separated by your user name and the registry address. So let me enter and in the form of password you need to provide. The authentication token that you just generated. So I'll paste the authentication token here and had entered as you can see I've currently logged in into my own registry. Now we can verify our setup using the fN list apps command to check which applications are created under our current context. So I'll go ahead and write FN list apps and it enter as you can see there's only one application which is currently created under the compartment function underscore demo called Hello world hyphen app. Now with this we complete our step three. Moving on to the step # four. As part of step four. We will be creating our first function. We will deploy it to the key functions and then we will invoke our function. So let's again switch back to the console. All right, so in order to create our first Hello World java function we'll have to use the FN in IT command. The FN innit. Runtime java. Hello. FN java command. What it does is it creates a directory called Hello FN java and creates several file under it. So let's go ahead and hit enter. As you can see it's created a Hello hyphen java directory which contains the function boilerplate as well as a function at the animal file which contains the function definition. Let me quickly do an Ls as you can see, we have this directory created. Let me move into this directory and do any less to show you the contents. All right, so as you can see we have a function or the ml file which contains the functions definition. We have an SRC directory which contains the java code and we also have a maven configuration file called pom dot xml that specifies the dependencies required to compile the function. All right, now that we have created our first Hello World java function we need to deploy it in order to deploy. This function will have to use the FN deploy command and also make sure that you must be inside the Hello hyphen java directory in order to run this command. So f n hyphen will deploy hyphen F in app and the application name which is Hello World hyphen app that made enter and as you can see what this command does is it builds the function and its dependencies as a docker image called Hello hyphen java and it pushes the image to the specified docker registry. And it will also deploy the function to the oracle functions in the Hello World hyphen app application which we created earlier. Now just to show you that the image that we created is loaded into an oc registry. Let's quickly go to the registry and see if we have an image called Hello hyphen Java with attack 0.0 point two available in the registry. So to go to the registry for shall minimize this cloud shell, click on the hamburger menu, go to the developers service and click on the container registry now within the container registry let's select the route compartment. And as you can see within this repository we have this image called Hello hyphen java with the tag 0.0 point two. So let's go back to the cloud shell let me quickly clear the screen now that we have deployed our function. It's time for us to invoke the first function that we just created in order to invoke your function. You can use the FN invoke command followed by the application name and the function name. Let me go ahead and hit enter for the first time. The FN invoke command will take some time for the function to load, right? There you go. We have the output of the function as Hello world. Now, if I read in this command again, it won't take as much time as it took earlier in order to invoke the function. Right? So this time the result was pretty quick. Now we can also invoke the function with parameters. For example, if I run this command, it will pass Mahendra Merah as a parameter to the function hello-java. Let's quickly run this command. And as you can see the output of the command is Hello, Mahindra mera, right. So with this we come to the end of this demo on functions. Quick start on cloud shell. I hope you like this demo. Thanks for watching.