@@ -483,30 +483,35 @@ import json
483483
484484app = func.FunctionApp()
485485
486- @app.function_name (name = " GetWeather" )
487- @app.queue_trigger (arg_name = " inputQueue" ,
488- queue_name = " input" ,
489- connection = " DEPLOYMENT_STORAGE_CONNECTION_STRING" )
490- @app.queue_output (arg_name = " outputQueue" ,
491- queue_name = " output" ,
492- connection = " DEPLOYMENT_STORAGE_CONNECTION_STRING" )
493- def queue_trigger (inputQueue : func.QueueMessage, outputQueue : func.Out[str ]):
494- try :
495- messagepayload = json.loads(inputQueue.get_body().decode(" utf-8" ))
496- location = messagepayload[" location" ]
497- weather_result = f " Weather is 82 degrees and sunny in { location} . "
498486
499- response_message = {
500- " Value" : weather_result,
501- " CorrelationId" : messagepayload[" CorrelationId" ]
487+ @app.function_name (name = " Foo" )
488+ @app.queue_trigger (
489+ arg_name = " arguments" ,
490+ queue_name = " azure-function-foo-input" ,
491+ connection = " AzureWebJobsStorage" )
492+ @app.queue_output (
493+ arg_name = " outputQueue" ,
494+ queue_name = " azure-function-tool-output" ,
495+ connection = " AzureWebJobsStorage" )
496+ def foo (arguments : func.QueueMessage, outputQueue : func.Out[str ]) -> None :
497+ """
498+ The function, answering question.
499+
500+ :param arguments: The arguments, containing json serialized request.
501+ :param outputQueue: The output queue to write messages to.
502+ """
503+
504+ parsed_args = json.loads(arguments.get_body().decode(' utf-8' ))
505+ try :
506+ response = {
507+ " Value" : " Bar" ,
508+ " CorrelationId" : parsed_args[' CorrelationId' ]
502509 }
503-
504- outputQueue.set(json.dumps(response_message))
505-
506- logger.info(f " Sent message to output queue with message { response_message} " )
510+ outputQueue.set(json.dumps(response))
511+ logging.info(f ' The function returns the following message: { json.dumps(response)} ' )
507512 except Exception as e:
508513 logging.error(f " Error processing message: { e} " )
509- return
514+ raise
510515```
511516
512517> ** Important:** Both input and output payloads must contain the ` CorrelationId ` , which must match in request and response.
@@ -522,8 +527,6 @@ To deploy your function to Azure properly, follow Microsoft's official documenta
522527** Summary of required steps:**
523528
524529- Use the Azure CLI or Azure Portal to create an Azure Function App.
525- - Enable System Managed Identity for your Azure Function App.
526- - Assign appropriate permissions to your Azure Function App identity as outlined in the Role Assignments section below
527530- Create input and output queues in Azure Storage.
528531- Deploy your Function code.
529532
@@ -536,31 +539,20 @@ To ensure that your Azure Function deployment functions correctly:
5365391 . Place the following style message manually into the input queue (` input ` ):
537540
538541{
539- "location": "Seattle",
540542 "CorrelationId": "42"
541543}
542544
543545Check the output queue (` output ` ) and validate the structured message response:
544546
545547{
546- "Value": "The weather in Seattle is sunny and warm. ",
548+ "Value": "Bar ",
547549 "CorrelationId": "42"
548550}
549551
550552---
551553
552554** Required Role Assignments (IAM Configuration)**
553555
554- Clearly assign the following Azure IAM roles to ensure correct permissions:
555-
556- 1 . ** Azure Function App's identity:**
557- - Enable system managed identity through Azure Function App > Settings > Identity.
558- - Add permission to storage account:
559- - Go to ** Storage Account > Access control (IAM)** and add role assignment:
560- - ` Storage Queue Data Contributor ` assigned to Azure Function managed identity
561-
562- 2 . ** Azure AI Project Identity:**
563-
564556Ensure your Azure AI Project identity has the following storage account permissions:
565557- ` Storage Account Contributor `
566558- ` Storage Blob Data Contributor `
0 commit comments