0
votes

I have Azure function annotations defined as below. Blob trigger reads data from Storage account processes and uses return value to write Output to a Blob container with "filename".json defined in the binding.

This is working as expected; however, when writing the data to a blob container. Output binding is checking for the existence of Blob with "GET" request and ultimately getting into 404 response code before making a "PUT" request. This was captured in Application Insights.

Is there any way I can override this behavior? Screen shot of Log analytics here

FUNCTION BINDINGS

public class ProcessZipFiles2Cosmos {
    
    @FunctionName("ProcessZipFiles2Cosmos")
    @StorageAccount("blobStorageAccount")
    @BlobOutput(name = "blob_redacted_json", path = "nonpii/{filename}.json")
    public static String run(
        @BlobTrigger(name = "files", dataType = "binary", path = "transactedreturn/{name}", connection = "blobStorageAccount") byte[] content,
        @BindingName("name") String filename,
        @CosmosDBOutput(name = "cosmos_transacted", databaseName = "tax-return-data-ops", collectionName = "TransactedReturns", 
                        connectionStringSetting = "AzureCosmosDBConnection") OutputBinding<String> cosmosItem,
        final ExecutionContext context) {
        
        // function body
    }
}

FUNCTION.JSON

{
   "scriptFile":"../transactedreturn-1.0.0-SNAPSHOT.jar",
   "entryPoint":"com.hrblock.clzconverter.ProcessZipFiles2Cosmos.run",
   "bindings":[
      {
         "type":"blobTrigger",
         "direction":"in",
         "name":"files",
         "path":"transactedreturn/{name}",
         "dataType":"binary",
         "connection":"blobStorageAccount"
      },
      {
         "type":"cosmosDB",
         "direction":"out",
         "name":"cosmos_transacted",
         "databaseName":"tax-return-data-ops",
         "connectionStringSetting":"AzureCosmosDBConnection",
         "collectionName":"TransactedReturns"
      },
      {
         "type":"blob",
         "direction":"out",
         "name":"$return",
         "path":"nonpii/{filename}.json",
         "connection":"blobStorageAccount"
      }
   ]
}
1

1 Answers

1
votes

When you say "override this behavior", I take it you want to circumvent the "exists" check, which ultimately is causing the 404 (as I see it), done by the Blob binding. While this would be possible, it would not really serve any real purpose. Is the expected 404 really that bad?

As to "why" it is happening, my guess is that it is happens while checking for existing container or other resources, needed for your specific Blob. It's hard to tell where it exactly happens, just from what we know, but the comment seen in the WebJobs SDK specifically calls ExistsAsync to limit the expected 40x status codes. If one dives into the Microsoft.Azure.Storage.Blob repo where the ExistsAsync is implemented, you can see the ExistsImpl expecting a 404 status code to determine whether the resource exists.

To circumvent the 404, you might be able to just use the BlobClient yourself, and just go straight ahead and create what you need created, without checking for existing resources. A fair warning though, this might ultimately cause far more issues than this expected 404 does (and tbh, the 404 is hardly causing any issues, as it is being handled by the SDK and storage lib).