Azure Functions

Les fonctions Azure permettent d'utiliser la technologie sans-serveur pour déployer facilement des applications sans-état. Elles peuvent être déclenchées par l'intermédiaire de différents types de déclencheurs; comme une requête HTTP, une modification de données dans un conteneur, ou encore un message.
Les fonctions sont associées à un Plan de Service, qui détermine les capacités techniques du système. Le code de la fonction sera lui même déployé dans un compte de stockage Azure.

Déclencheurs (triggers)

Schedule

The code segment that includes Run([TimerTrigger("0 */15 * * * 1-5") executes the function every 15 minutes from Monday to Friday. 
The code segment that includes Run([TimerTrigger("*/15 * * * 0-4") is missing the second part, and it is not using the proper range for days of the week. 
The code segment that includes Run([TimerTrigger("0 15 * * * ") executes only once at 15:00 (3 PM).
The code segment that includes Run([TimerTrigger("* 15 * * 1-5") is missing the seconds attribute and the step (‘/’) part for the minutes.

https://learn.microsoft.com/training/modules/execute-azure-function-with-triggers/


 the feedPollDelay parameter to 0, because this controls how frequently the Azure Functions change feed processor polls for new changes in the Cosmos DB container. By default, there is a delay (typically 5 seconds) between polls to balance responsiveness and cost. Setting it to 0 ensures the function reads changes from Container1 immediately, which meets the requirement without needing to upgrade the hosting plan. Configuring the function to use the Consumption or Premium plan does not directly affect how quickly change feed events are read. Setting feedPollDelay to -1 is invalid and would not achieve the desired result. Therefore, adjusting feedPollDelay to 0 is the most cost-effective solution.

Mise à l'échelle (scalability)

Mise à l'échelle horizontale (Scale Out)


Imposing limits on the scaling out capacity of an Azure Functions app can help when the app connects to components that have limited throughput. The functionAppScaleLimit property lets you define the number of instances of the Azure Functions app that will be created. Therefore, setting it to a low value, such as 10, is appropriate in this scenario. Azure Functions apps in the Consumption plan can scale out and have 200 instances as a default. A value of 0 or null for the functionAppScaleLimit property means that an unrestricted number of instances of the Azure Functions app will be created.

Limitation API tierce (third party throthling)

Setting the 'maxConcurrentRequests' property in the host.json file will limit the number of HTTP functions that are executed in parallel, which can help manage resource utilization and avoid exceeding the rate limit of the third-party service. 

The 'maxOutstandingRequests' property limits the number of outstanding requests that are held at any given time, including queued requests and in-progress executions, which can also help manage resource utilization. 
Enabling 'dynamicThrottlesEnabled' property rejects requests based on system performance counters, not based on the rate limit of a third-party service. 
The 'hsts' property is used to enforce HTTP Strict Transport Security (HSTS) behavior and is not related to managing resource utilization or rate limiting. 
The 'routePrefix' property is used to set the route prefix for all routes and does not affect resource utilization or rate limiting.

Sécurité d'accès des fonctions

Parlons d’abord des niveaux d’autorisation dans les fonctions Azure. Le premier paramètre de l'attribut HttpTrigger dans la fonction Azure est le type d'autorisation requis pour appeler la fonction.

AuthorizationLevel est une énumération et peut prendre les valeurs suivantes. 
  • Anonyme : aucune authentification requise
  • Fonction : Autorisation au niveau de la fonction
  • Utilisateur : autorisation au niveau de l'utilisateur
  • Système : Autorisation au niveau de l'application de fonction
  • Administrateur : autorisation d'administrateur.
L’application de fonction Azure peut héberger plusieurs fonctions. La fonction de déclenchement HTTP en fait partie.

Clés Hôte

Lorsque nous créons une application de fonction Azure, elle crée automatiquement deux clés d'application, default et _master. C'est ce qu'on appelle des clés d'hôte. Les clés hôte sont applicables à toutes les fonctions de l’application de fonction et peuvent être utilisées pour appeler toutes les fonctions de l’application de fonction.

Clés de Fonction

Toute fonction Azure (sans AuthorizationLevel.Anonymous) que vous ajoutez dans l'application de fonction générera une clé de fonction nommée par défaut, valable uniquement pour cette fonction particulière.

Elles peuvent être déployées facilement via AzureDevOps et la tache AzureFunctionApp@1.

KeyVault

Using User Assigned identity for keyvault references.

AppSettings
    "keyVaultReferenceIdentity"       = azurerm_user_assigned_identity.grace_id.id

Terraform Property
 // identity for KV access
  key_vault_reference_identity_id = azurerm_user_assigned_identity.grace_id.id

Service Plans

The Premium plan avoids cold starts and offers unlimited execution duration. 
The fan-out/fan-in pattern enables multiple functions to be executed in parallel, waiting for all functions to finish. Often, some aggregation work is done on the results that are returned from the functions. 
The Consumption plan avoids paying for idle time but might face cold starts. 
Furthermore, each function run is limited to 10 minutes. 
The function chaining pattern is a sequence of functions that execute in a specific order. In this pattern, the output of one function is applied to the input of another function.

Ressources

  • https://learn.microsoft.com/en-us/azure/azure-functions/function-keys-how-to
  • https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger
  • https://learn.microsoft.com/fr-fr/azure/app-service/app-service-key-vault-references
  • https://learn.microsoft.com/en-us/azure/app-service/app-service-key-vault-references?tabs=azure-cli#access-vaults-with-a-user-assigned-identity

Commentaires

Posts les plus consultés de ce blog

Conception logicielle en 2024

DeFi - Définition

Modèles de Conception de Construction