Question:
You are responsible for creating a serverless application that communicates with an API. This application will ingest data through HTTP requests and, dependent on the received data, it must modify a structured NoSQL database in the cloud. This database should have a key/attribute store with a schemaless design. Could you outline how you would construct the Azure Function to fulfill this purpose? Please provide the triggers and bindings in the code below:
[FunctionName("UpdateDatabase")]
public static async Task<IActionResult> Run(
/* Triggers and Bindings here */
ILogger log)
{
// Parse the incoming data
// Add the processed data to storage
// Return a success response
}
Answer:
This is an example of an HTTP Trigger. The Azure function can be activated by an HTTP request containing the data. In response to the data received, the function could use an output binding to a structured NoSQL service, Azure Table Storage in this case, to modify the database accordingly.
[FunctionName("UpdateDatabase")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
HttpRequest req,
[Table("<table-name>", Connection = "<storage-connection-string>")]
IAsyncCollector<dynamic> outputTable,
ILogger log)
{
// Parse the incoming data
// Add the processed data to storage
// Return a success response
}