Where can i find the code of an Azure Function?
Asked Answered
N

3

5

I'm new to Azure Functions and been thrown into a project without a proper introduction and anybody I could ask is out of office. My simple most likely stupid question is; where can I find the actual code?

In the azure portal, the functions are listed as "read-only" and only contains a function.json. The resource is an App Service and it has a couple of functions. There is no link to any git repository in properties.

Nightcap answered 18/7, 2018 at 9:13 Comment(3)
Most probably they are compiled functions then. They would probably be in your company's version control system. This question is not really a good question for SO since we cannot know where your coworkers have left the code.Conformable
Sounds logical. Thanks! I agree that this question is not for SO then. But maybe a more relevant question to ask is if there is anyway of finding the repo that is deployed to the azure function?Nightcap
Yeah, that is actually a sound question. I think you can only see that if it is configured from the Function side. Not if they are just deploying from a CD process/manually.Conformable
E
7

Read-only Functions would be compiled and published (e.g. through Visual Studio or a CI/CD pipeline.) The Azure Functions Portal engineers are working on a new, improved experience for this but for now, if your Function app has a deployment source configured, you can view it from the Portal in two ways from your Function app:

  1. Platform Features > Deployment Options.
  2. Platform Features > Resource Explorer. In the file tree on the lefthand side, find your Function app's name, and under that, sourcecontrols. Click to expand in the righthand window.

If your Function app doesn't have a deployment source configured (e.g. your team has been publishing code manually) then things get harder. Depending on how your company has set up their source control and what you already have access to, the function.json you see might help: the entryPoint property in a build-generated function.json will give you the full assembly name of that function (e.g. VSSample.HelloSequence.Run). That or the assembly name of the uploaded DLL in the scriptfile property might help you locate the project.

Good luck! Keep posting if you have further questions; we're here to help.

Entelechy answered 18/7, 2018 at 21:20 Comment(2)
So in short, the function's source code can't be retrieved if it wasn't versioned somewhere ? Say the function exists and is running, but the code is nowhere except within the deployed Azure function... How do I retrieve it?Pender
@Aetos that would be exactly the same as having a compiled app in any runtime environment - if you don't have the source code, you don't have the source code, and you're looking at decompiling and the like. Azure Functions doesn't change that particular situation in any way. See https://mcmap.net/q/1979697/-where-can-i-find-the-code-of-an-azure-function for where you can get the binaries from.Abundant
R
1

AFAIK, if we create the azure function in the Visual Studio and publish it to Azure(there may be other ways), it will appear in the situation you described like the screenshot.

enter image description here

Actually, the code is existing in the portal, but the code has been compiled, you could access it in the Platform features -> Advanced tools (Kudu) -> Debug console.

enter image description here

If you want to get the .cs file, I think you should ask it for your coworkers, there will not be in azure.

Respondent answered 18/7, 2018 at 10:3 Comment(0)
A
0

You said that the Azure function is listed as "read-only". Did you check from the Application Settings menu if you can change the Azure function app edit mode to Read/Write?

Abednego answered 18/7, 2018 at 9:31 Comment(1)
I was able to change it to "Read/Write" in Application Settings. But the code is still just a function.json, so i'm guessing the actual code of the functions is somewhere else as the they runs and performs a somewhat intelligent task.Nightcap

© 2022 - 2024 — McMap. All rights reserved.