@@ -483,30 +483,35 @@ import json
483
483
484
484
app = func.FunctionApp()
485
485
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} . "
498
486
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' ]
502
509
}
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)} ' )
507
512
except Exception as e:
508
513
logging.error(f " Error processing message: { e} " )
509
- return
514
+ raise
510
515
```
511
516
512
517
> ** 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
522
527
** Summary of required steps:**
523
528
524
529
- 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
527
530
- Create input and output queues in Azure Storage.
528
531
- Deploy your Function code.
529
532
@@ -536,31 +539,20 @@ To ensure that your Azure Function deployment functions correctly:
536
539
1 . Place the following style message manually into the input queue (` input ` ):
537
540
538
541
{
539
- "location": "Seattle",
540
542
"CorrelationId": "42"
541
543
}
542
544
543
545
Check the output queue (` output ` ) and validate the structured message response:
544
546
545
547
{
546
- "Value": "The weather in Seattle is sunny and warm. ",
548
+ "Value": "Bar ",
547
549
"CorrelationId": "42"
548
550
}
549
551
550
552
---
551
553
552
554
** Required Role Assignments (IAM Configuration)**
553
555
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
-
564
556
Ensure your Azure AI Project identity has the following storage account permissions:
565
557
- ` Storage Account Contributor `
566
558
- ` Storage Blob Data Contributor `
0 commit comments