Top Azure Functions Interview Questions (2021) | CodeUsingJava
















Most frequently Asked Azure Functions Interview Questions


  1. What is Azure Functions?
  2. What is Azure Redis Cache?
  3. How can we use NuGet packages in my Azure Functions?
  4. What is the simplest way to run a timer-triggered Azure Function locally?
  5. What is Azure Functions Database Connection String?
  6. How to rename an Azure Function?
  7. How can we return JSON from an Azure Function?
  8. What are the features of Azure Functions?
  9. How can we configure Log Level for Azure Functions?
  10. How can I do Routing in Azure Functions?

What is Azure Functions?

Azure Functions allows us to write codes and maintain less infrastructure and save on costs.It helps in performing tasks like image processing, processing orders, file maintenance and in running scheduled tasks.

What is Azure Redis Cache?

Azure Redis Cache is a version of an open source Cache that makes it east for us in adding Redis to our applications which are running in Azure.It is an in memory database where data is stored in as a key value pair so the keys can contain data structures such as strings, hashes, and lists.

How can we use NuGet packages in my Azure Functions?

Azure Functions portal does not currently provide a mechanism to add and manage NuGet packages, the runtime supports NuGet references and will make sure they are correctly used when compiling and executing your functions.
Here is an example that adds a reference:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.ProjectOxford.Face": "1.1.0"
      }
    }
   }
}


What is the simplest way to run a timer-triggered Azure Function locally?

We can refer to a cron expression in the app settings:

public static void Run([TimerTrigger("%TimerSchedule%")]TimerInfo myTimer, TraceWriter log)



What is Azure Functions Database Connection String?

We can access an external database to execute the function.

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true;",
    "AzureWebJobsDashboard": ""
  },
  "ConnectionStrings": {
    "MyConnectionString": "[YourConnectionStringHere]"
  }
}

This allows us to use the ConfigurationManager.ConnectionStrings[] we are all used to.

var sqlConnection = ConfigurationManager
                   .ConnectionStrings["MyConnectionString"].ConnectionString;


How to rename an Azure Function?

Open the Console from your Function APP.
Rename the Function folder using command line.
Restart the Function.
Refresh.

Azure


How can we return JSON from an Azure Function?


#r "Newtonsoft.Json"

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info($"Running Function");    
    try {      
      log.Info($"Function ran");

      var myJSON = GetJson();

      // I want myJSON to look like:
      // {
      //   firstName:'John',
      //   lastName: 'Doe',
      //   orders: [
      //     { id:1, description:'...' },
      //     ...
      //   ]
      // }
      return ?;
    } catch (Exception ex) {
        // TODO: Return/log exception
        return null;
    }
}

public static ? GetJson()
{
  var person = new Person();
  person.FirstName = "John";
  person.LastName = "Doe";

  person.Orders = new List<Order>();
  person.Orders.Add(new Order() { Id=1, Description="..." });

  ?
}

public class Person
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public List<Order> Orders { get; set; }
}

public class Order
{
  public int Id { get; set; }
  public string Description { get; set; }
}




What are the features of Azure Functions?

The following are the features of Az Functions:
  • Intuitive, browser-based user interface - It is easy for using web interface or in using our development tool in building and debugging.
  • Variety of programming languages - We can choose the programming language of our choice, as it accepts a variety of programming languages such as C#, F#, Node.js, Python, PHP or Java.
  • Capabilities for implementing code - It implement code triggered by events occurring in any third-party service or on-premise system.
  • Supports Continuous Deployment and Integration - Helps in supporting Continuous Deployment and Continuous Integration.
  • Portable Runtime - It helps in deploying serverless applications on any public cloud or your own internal network. Implement custom features - Helps in implementing custom features with this platform because runtime, templates, UI and underlying WebJobs SDK.

How can we configure Log Level for Azure Functions?


{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Information",
      "Host.Results": "Error",
      "Function": "Trace",
      "Host.Aggregator": "Trace"
    }
  }
}



How can I do Routing in Azure Functions??

{
    "bindings": [
        {
            "type": "httpTrigger",
            "name": "req",
            "direction": "in",
            "methods": [ "post", "put" ],
            "route": "node/products/{category:alpha}/{id:guid}"
        },
        {
            "type": "http",
            "name": "$return",
            "direction": "out"
        },
        {
            "type": "blob",
            "name": "product",
            "direction": "out",
            "path": "samples-output/{category}/{id}"
        }
    ]
}