0

I have made a simple Azure Function with blob trigger. It is working fine in my development environment using Azure storage Explorer. However, when I created the function in Azure portal it is not working.

I also want to mention that it is free subscription account, so it never asked me to select the storage account while creating function (Check snapshot below).

enter image description here

I have already added the storage connection string (Check snapshot below).

enter image description here

If I check the monitoring invocation, it gives zero success and 0 failure, means it never even triggered.

enter image description here

Moreover, if I run the diagnose, it is giving me a suggestion to create two settings, WEBSITE_CONTENTSHARE and WEBSITE_CONTENTAZUREFILECONNECTIONSTRING.

enter image description here

In "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING" storage account connection string will be used but what should I configure in "WEBSITE_CONTENTSHARE"?

Following is the C# function code:

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Processing;

namespace ThumbnailGenerator
{
    public class ThumbnailFunction
    {
        [FunctionName(nameof(ThumbnailFunction))]
        public void Run([BlobTrigger("wpm/{name}", Connection = "wpmStorageConn")]Stream myBlob,
            [Blob("thumbnail/{name}",FileAccess.Write, Connection = "wpmStorageConn")] Stream outputStream, string name, ILogger logger)
        {
            logger.LogInformation($"Function triggered for wpm container\n Name:{name} \n Size: {myBlob.Length} Bytes");

            //Stream outputStream= null;k
            resize(myBlob, ref outputStream);

            logger.LogInformation("Thumbnail created");

        }

        private static void resize(Stream myBlob, ref Stream outputStream)
        {
            using (Image image = Image.Load(myBlob))
            {
                int width = 50;
                int height = 0;
                image.Mutate(x => x.Resize(width, height));

                image.Save(outputStream, JpegFormat.Instance);
            }
        }
    }
}
0

1 Answer 1

0

In the Azure free trial subscription, you may not be able to create a storage account along with an Azure Function App due to limited access.

  1. The WEBSITE_CONTENTSHARE and WEBSITE_CONTENTAZUREFILECONNECTIONSTRING settings are required default settings and will not be automatically created when you create a Function App as storage account is not getting created with function app.

  2. To resolve this, you need to create a storage account separately and then add the storage account’s connection string to the AzureWebJobsStorage and WEBSITE_CONTENTAZUREFILECONNECTIONSTRIN in the Function App’s Environment variables under App settings'.

  3. For WEBSITE_CONTENTSHARE you need to create a file share in the same storage account shown below and add the file share name to the Environment variables.

enter image description here

  1. Add the following values in the Environment variables as shown below.
AzureWebJobsStorage : <storage account connection string>
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING : <storage account connection string>
WEBSITE_CONTENTSHARE : <file share name>

enter image description here

I created the below simple Blob trigger function in VS code.

import azure.functions as func
import logging

app = func.FunctionApp()

@app.blob_trigger(arg_name="myblob", path="mycontainer",
                               connection="kamfuncpyst_STORAGE") 
def blob_trigger(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob"
                f"Name: {myblob.name}"
                f"Blob Size: {myblob.length} bytes")

local.settings.json :

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "<connect_string>",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "kamfuncpyst_STORAGE": "<connect_string>"
  }
}

After deploying the Blob trigger function to the Azure Function App, I added the storage account connection string from the local.settings.json file to the Function App's environment variables, as shown below.

enter image description here

The Blob trigger function ran successfully as shown in the below Invocations.

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

I followed the same steps, but it is not working.
@MuhammadAshharHasan Ok, Can you share your code in the question?
Code also added in the question and that code is working fine in my local development environment
@MuhammadAshharHasan I Will check and let you know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.