Complete the code to define an input binding for an Azure Function that triggers on a Blob storage event.
public static void Run([BlobTrigger("[1]/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, ILogger log) { log.LogInformation($"Blob trigger function processed blob: {name}"); }
The input binding for BlobTrigger requires the container name where blobs are stored. Here, 'input-blobs' is the correct container name used in the binding path.
Complete the code to define an output binding that writes a message to an Azure Queue.
public static void Run(string input, [Queue("[1]", Connection = "AzureWebJobsStorage")] out string outputMessage, ILogger log) { outputMessage = input.ToUpper(); log.LogInformation("Message sent to queue."); }
The output binding for Queue requires the queue name. 'output-queue' is the correct queue name where messages will be sent.
Fix the error in the output binding attribute to correctly write to a Cosmos DB collection.
public static void Run(string input, [CosmosDB(databaseName: "MyDb", collectionName: "[1]", ConnectionStringSetting = "CosmosDBConnection")] out dynamic document, ILogger log) { document = new { id = Guid.NewGuid().ToString(), content = input }; log.LogInformation("Document written to Cosmos DB."); }
The Cosmos DB output binding requires the collection name. 'MyCollection' is the correct collection name in this context.
Fill both blanks to create an Azure Function that reads from a Service Bus queue and writes to a Blob storage output.
public static void Run([ServiceBusTrigger("[1]", Connection = "ServiceBusConnection")] string myQueueItem, [Blob("[2]/{rand-guid}.txt", FileAccess.Write, Connection = "AzureWebJobsStorage")] out string outputBlob, ILogger log) { outputBlob = myQueueItem; log.LogInformation("Message processed and saved to blob."); }
The ServiceBusTrigger input binding uses the queue name 'input-queue'. The Blob output binding writes to the container 'output-container'.
Fill the blanks to define an Azure Function with an HTTP trigger input, a Cosmos DB output, and a Queue output binding.
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
[CosmosDB(databaseName: "MyDb", collectionName: "[1]", ConnectionStringSetting = "CosmosDBConnection")] IAsyncCollector<dynamic> documentsOut,
[Queue("[2]", Connection = "AzureWebJobsStorage")] IAsyncCollector<string> queueOut,
ILogger log) {
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
await documentsOut.AddAsync(new { id = Guid.NewGuid().ToString(), content = requestBody });
await queueOut.AddAsync(requestBody);
log.LogInformation("Data saved to Cosmos DB and queue.");
return new OkResult();
}The Cosmos DB output binding uses 'MyCollection' as the collection name. The Queue output binding uses 'output-queue' as the queue name. 'MyDocuments' is not used in this code but is a distractor option.