Ideally how many functions should be there in a fucntion app - azure

As per the new template in Visual Studio 2017 prev 2, all function in a function app do share dependencies. Any custom business code/library added will be available to all other functions in a function app.
There is a problem here that it is will give monolithic design a chance to sneak in. And any change in a function would require entire set of function to be redeployed.
Another design can be to keep the function app as thin as possible (if possible one function per function app in my opinion). This would segregate the code and dependencies of each function, but on the flip side, I would bring a deployment/maintainability nightmare.
Is there any design guideline to be followed which could balance maintainability hassle and help achieving micro service design goal ?

It's up to you how much you want to group together vs be separate on their own. You can also have all your functions in 1 project in Visual Studio then deploy it to N number of function apps, then you can specify which functions a given function app should run in your host.json. Check the functions property in here https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json
Note that the Portal UI doesn't handle that correctly now, so you may get odd errors if you go in the portal. Tracked here https://github.com/Azure/azure-functions-ux/issues/1428

Related

Get firebase function url from admin SDK programatically

Is there a way to get the Firebase Function url from the Admin SDK for nodejs?
In prod it will look like: https://REGION-PROJECT.cloudfunctions.net/FUNCTION_NAME
And when serving locally: http://localhost:PORT/PROJECT/REGION/FUNCTION_NAME
Is it possible to get this value in nodejs programmatically? E.g. from admin or configuration settings?
The Firebase Admin SDK doesn't expose any APIs that deal with Cloud Functions. From what you've shared, it sounds like you have everything you need to build the URL yourself, which is the right way to go.
If you really must use another piece of software, you'll have to dive very deep into the inner workings of the Firebase CLI and figure out how to reuse its code. You'll probably have to look in two places - one for the emulator, and another for deployment. I suspect this is almost certainly not going to be worth your time, since building the strings yourself is pretty straightforward.
Since you don't say exactly what you want to accomplish, I'll just guess that you want your app to be aware of when you're in development vs. production mode.
What I did was to simply write in some checks in my front- and back-end code. For instance, in the browser/web code:
if (window.location.href.toString().includes('localhost:5000')) {
// exhibit desired behavior for emulator
} else {
// exhibit desired behavior for production
}
Depending on how you're calling your node/backend functions, you could pass along the execution context (emulated or production), and use that in the back, too.
It's not perfect, but it's actually streamlined development for me quite a bit. Hope that helps!

Multiple Azure App Function in a project

I'm currently developing a small game that will rely on a lot Azure App Functions to execute function from time to time. I followed a tutorial on MSDN (https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs#configure-the-project-for-local-development) explaining that I had to create a new project to host a function but so far, I already have 6 different functions and I don't really want to create 6 different projects.
Moreover, all these functions (developed in JavaScript) have a lot of code in common so I created a common JavaScript file with some helper function. Now that I have multiple projects, I can't use it anymore without copy/pasting it in all projects.
Finally, to be able to correctly develop the game, all the functions must be running in parallel on my development machine and I don't really want to open 6 (or more in the future) powershell instances to host these functions.
Is there a way to host multiple functions in the same project and deploy them easily on Azure ?
That's what Function Apps are for. Each Function App may contain multiple Functions, which will be deployed together.
You mention Javascript, but the linked tutorial is in C#. Regardless, you can put multiple functions into the same app: subfolders under the same root (where host.json file is), or static methods in the same C# project. Each function will have a separate function.json file. All functions can share the same code.

How to share common code among the Azure functions?

I have common code which is require in other Azure functions, how can I share the common code among the Azure functions?
If the Functions you are wanting to share code between are under the same Function App you can do the following:
https://stackoverflow.com/a/39541156/2854993
And if they are separate Function Apps, I asked a similar question - see:
Azure Functions - Shared code across Function Apps
I managed to get shared code to work (or rather: compile) using an Azure Function Tools for Visual Studio project. In case of the screenshot, the shared library is actualy another Function project. I also tried to work with class libraries: those seem to work as well.
Haven't gotten around to deploying it yet, by the way. Running (and debugging) it localy is not an issue, so I guess deploying shouldn't be one either.

Azure Functions - Shared code across Function Apps

Is there a way of sharing common code across two different Function Apps in Azure?
I understand it is possible to share code between two functions under the same Function App like so:
#load "../Shared/ServiceLogger.csx"
but I would like to share logging code between two different functions, each under it's own Function App. The reason for the functions being under two different Function Apps is that I need one to run on the Consumption plan and the other run on an App Service plan, unless there is another way of doing this?
There is no straightforward way to share code across app boundary in Azure App Sercice, and this holds true both for Function Apps and Web Apps. You will need to deploy the relevant code into each app that needs it.
What I did to get around this before the fix in VS17 Preview (which treats functions as normal cs files and allows project references) is I had a shared class project that had a post build event that would put the dlls into the Azure function projects in a folder. Then reference them with #r "file path to the dll"
One way to reuse code is to use precompiled assemblies / class libraries with your Functions. Donna Malayeri has published a blog post explaining how to achieve this: https://blogs.msdn.microsoft.com/appserviceteam/2017/03/16/publishing-a-net-class-library-as-a-function-app/
Consequently, you could have 2 or more different Functions, deployed to different AppServices or Function instances sharing the same code through a class library. Precompiled assemblies are supported in .NET C# Functions and you can do something similar using WebPack in Node.js based Functions

Azure functions calling onto native C++

I'm designing a new architecture in Azure. It's a multi-tenant SaaS application with an ASP.NET MVC front end and some application specific data in blob storage. I need to perform some background processing on this application data at certain points. This is currently only possible using some legacy C++ code (I can't realistically rewrite this in C#).
One thought I had was to push any background jobs onto a queue and use Azure functions to service the queue as and when a job gets pushed onto it. The sticking point is the native code. I can certainly expose methods in the native code that C# can p/invoke, but can Azure functions call onto native DLLs and if so is this a sensible approach?
The code does run in a sandbox, but this approach should work. (you may want to consider exposing the relevant API in a managed assembly that would in turn be consumed by your function).
Whether you'll run into limitations with the sandbox is dependent on what your code is doing, but you can learn more about the sandbox and its restrictions here: https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox
I hope this helps!
mfcu100.dll likely depends on some other DLL inside the VC++ 2010 Redist
Most probably msvcr100.dll and msvcp100.dll.
If you include all the dependency DLLs along with your native binary, it should work.

Resources