1
votes

I want to create and host a azure function that would take as input "azure-storage-account-name" and "path" and run some common logic and then return a list of processed blobs in that storage account at that path. I have 20 storage accounts and I was thinking to write single azure function in same subscription to have listing capability across all of them

I went through Azure function documentation couldn't figure out if this is even possible in current offering. Any pointers would be helpful

2
you also need a key to access the storage account unless you have made the folders publicviperguynaz
Any particular reason why you would do that using a function instead of the Azure Blog Storage - List Blobs ? You could also do it in a Function, using the Azure Storage Library nuget package. Keep in mind that you'll need to store the storage connection strings for each storage account as well then.Steven Van Eycken
When you say path ? you mean filename or every file in a container or in specific folder ?Thomas
Actually the idea is not only to list, but also delete the ones that are no longer needed. The logic is same for blobs across storage accounts. Hence, I need this functionality abstracted out so that its called for each storage account externally (say logic app)Illuminati

2 Answers

1
votes

You can use Imperative Bindings feature of Azure Functions. This is a sample code:

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, Binder binder, TraceWriter log)
{
    var attributes = new Attribute[]
    {
        new StorageAccountAttribute("your account"),
        new BlobAttribute("your folder name")
    };

    var directory = await binder.BindAsync<CloudBlobDirectory>(attributes);
    log.Info(directory.ListBlobs().Count().ToString());

    return new HttpResponseMessage(HttpStatusCode.OK);
}
0
votes

If you have the correct credentials, you can use the Azure Storage REST API to get a list of containers