1

I am looking for the appropriate resources/tutorials that could help me develop and deploy an Event Grid Trigger that would wait for an image upload to a blob container, process that image using python, then save the results in another blob container. I have found many separate pieces of documentation which don't necessarily logically walk me through developing and deploying using the Azure Portal and VSCode, like a step-by-step walkthrough from beginning to end, of all the steps to make this possible.

Any guidance would be greatly appreciated.

1
  • Hi, any update? Commented Nov 30, 2020 at 2:46

1 Answer 1

5

I don't recommand you to use Azure portal directly to develop. And since you need to use develop Azure function based on Python, then you need to use Azure function core tools.

1, Download and install Azure function core tools.(download the function3.x)

https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#v2

And you need to install python 3.8.x(Please notice you must download 64bit. Otherwise function app will face error when start.)

2, Configure the Python to the system path.

3, install function extension and Python debug extension in VS code.

4, press f1 and input 'func', you will find the create function options.

5, Follow the steps you will create the function. Then use below code:

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    },
    {
      "name": "inputblob",
      "type": "blob",
      "path": "test1/6.txt",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "path": "test2/6.txt",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    }
  ]
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "MyStorageConnectionAppSetting":"DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx==;EndpointSuffix=core.windows.net"
  }
}

__init__py

import json
import logging

import azure.functions as func


def main(event: func.EventGridEvent, inputblob: func.InputStream, outputblob: func.Out[func.InputStream]):
    result = json.dumps({
        'id': event.id,
        'data': event.get_json(),
        'topic': event.topic,
        'subject': event.subject,
        'event_type': event.event_type,
    })

    logging.info('Python EventGrid trigger processed an event: %s', result)

    #Do something here. you can change below inputblob to other stream.

    outputblob.set(inputblob)

After all of the above steps, create a event grid subscription and deploy your function app to azure. Point the event grid to your function app. Then When A event comes, the function will be triggered.

The thing you need notice is Binder not supported in Python, so...the path can not be specified in running.(This is a pity. Ibinder only supported for .Net based language.)

Above is your requirement, It can works but the blob path cannot be dynamic... I think for your situation, the more suitable way is to use blobtrigger and blob output binding.(This can get the blob name from trigger to output.)

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

1 Comment

Quick steer: it is appreciated here if you can run an English spelling-checker on your work before submitting. Any variant of English is perfectly fine. Most browsers support a spelling-checking these days, and often are already installed with one.

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.