Question:
Imagine you're part of an organization that operates in the cloud and manages numerous resources across a wide variety of Azure subscriptions. For compliance and auditing purposes, the company aims to log all changes to resource states. Considering that your organization operates worldwide, requiring the data to be available without significant latency regardless of the location, which Azure service would you recommend to trigger your Azure Function? Fill in the triggers and bindings in the code provided:
[FunctionName("LogResourceChanges")]
public static void Run(
/* Triggers and Bindings here */
ILogger log)
{
// Process the incoming event
// Prepare the document based on the event data
// The document is automatically added to storage
}
Answer:
For this scenario, an Event Grid trigger would be ideal. Azure Event Grid is capable of dispatching an event whenever there is a state change in Azure resources, which in turn triggers your Azure Function. Following activation, the function could log these changes to a data service that can offer seamless access to data from any corner of the world, such as Azure Cosmos DB, using an output binding. This would ensure that no matter where the request is coming from, data access will remain consistent and fast, supporting your global operations.
[FunctionName("LogResourceChanges")]
public static void Run(
[EventGridTrigger]
EventGridEvent eventGridEvent,
[CosmosDB("<database-name>", "<collection-name>", ConnectionStringSetting = "CosmosDBConnectionString")]
out dynamic document,
ILogger log)
{
// Process the incoming event
// Prepare the document based on the event data
// The document is automatically added to storage
}