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.)