Question:
A customer is keen on setting up a system that is capable of accepting JSON payloads from an assortment of services. This payload data is then intended to be stored in a database that is optimal for storing large amounts of structured, non-relational data, such as metadata, user data, and diagnostic data. How would you structure an Azure Function to accommodate this need? Please provide the triggers and bindings in the following code.
[FunctionName("ProcessPayload")]
public static async Task<IActionResult> Run(
/* Triggers and Bindings here */
ILogger log)
{
// Process incoming JSON payload data
// Add the processed data to designated storage
// Return a success response
}
Answer:
In this circumstance, an HTTP trigger could be employed to receive the JSON payloads. The payload data could then be stored into a database service that is designed for storing structured NoSQL data using an output binding - in this case, Azure Table Storage.
[FunctionName("ProcessPayload")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
HttpRequest req,
[Table("<table-name>", Connection = "StorageConnectionAppSetting")]
IAsyncCollector<dynamic> outputTable,
ILogger log)
{
// Process incoming JSON payload data
// Add the processed data to designated storage
// Return a success response
}