503 Service Unavailable while executing an azure function

khouloud Belhaj 91 Reputation points
2021-08-20T13:21:22.503+00:00

Hello;

I created an azure function that connects to Power BI service, retrieves logs and saves data in a Storage blob. Knowing that the service principal has access to all workspaces. There is a large number of datasets related to each workspace. My function runs almost several attempts. I would like to know how to solve this problem knowing that I cannot expand my resources.

Here is the code of the function :

   using namespace System.Net  

   # Input bindings are passed in via param block.  
   param($Request, $TriggerMetadata)  


   # Interact with query parameters or the body of the request.  
   $name = $Request.Query.Name  
   if (-not $name) {  
   $name = $Request.Body.Name  
   }  
   $body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."  


   if ($name) {  


   #Initialisation des paramétres d'identification pour le service principale  
   $appId = $env:APP_ID  
   $tenantId = $env:APP_TENANT_ID  
   $secret = $env:APP_SECRET  
   $password = ConvertTo-SecureString $secret -AsPlainText -Force  
   $Cred = New-Object System.Management.Automation.PSCredential ($appId, $password)  
   #Write-Output $Cred  
   [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12  
   #configure proxy  
   $webclient=New-Object System.Net.WebClient  
   $webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials  
   #Connexion au service POWER BI  
   Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $tenantId -Credential $Cred  
   #Write-Host $name  
   for($i=0;$i -lt $name;$i++)  
   {  
   $activitiesDate = [System.DateTime]::Now.Date.AddDays(-$i)  
   $dateTimeStart = $activitiesDate.Date.ToString("s")  
   $dateTimeEnd =  $activitiesDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59).ToString("s")  
   Write-Host $activitiesDate  
   Write-Host $dateTimeStart  
   Write-Host $dateTimeEnd  
   #activities = Get-PowerBIActivityEvent -StartDateTime $dateTimeStart -EndDateTime: $dateTimeEnd | ConvertFrom-Json  
   #Récuperation des données logs  
   $activities = Get-PowerBIActivityEvent -StartDateTime $dateTimeStart -EndDateTime $dateTimeEnd | ConvertFrom-Json  
   Write-Host $activities  
   $psObjectForCsv = $activities | ForEach-Object {  
       [PSCustomObject]@{  
           "id"=$_.Id  
           "RecordType" = $_.RecordType  
           "CreationTime" = $_.CreationTime  
           "Operation" = $_.Operation  
           "OrganizationId" = $_.OrganizationId  
           "UserType" = $_.UserType  
           "UserKey" = $_.UserKey  
           "Workload"=$_.Workload  
           "UserId"=$_.UserId  
           "ClientIP"=$_.ClientIP  
           "UserAgent"=$_.UserAgent  
           "Activity"=$_.Activity  
           "ItemName"=$_.ItemName  
           "WorkSpaceName"=$_.WorkSpaceName  
           "DatasetName"=$_.DatasetName  
           "ReportName"=$_.ReportName  
           "WorkspaceId"=$_.WorkspaceId  
           "ObjectId"=$_.ObjectId  
           "DatasetId"=$_.DatasetId  
           "ReportId"=$_.ReportId  
           "EmbedTokenId"=$_.EmbedTokenId  
           "IsSuccess"=$_.IsSuccess  
           "ReportType"=$_.ReportType  
           "RequestId"=$_.RequestId  
           "ActivityId"=$_.ActivityId  
           "DistributionMethod"=$_.DistributionMethod  
           "ConsumptionMethod"=$_.ConsumptionMethod  

       }  
   }  

   }   

   #saving data in the output file blob   

   Push-OutputBinding -Name outputBlob -Value $psObjectForCsv  

   Write-Host $psObjectForCsv  


   }  

Here is the error that is shown.

![125074-image.png]1

Any help will be appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,326 Reputation points Microsoft Employee Moderator
    2021-09-21T15:25:58.207+00:00

    To benefit the community, @khouloud Belhaj 503 issue was the result of high memory consumption which exceeded the limits of the consumption plan. The best resolve for this issue is switching to a dedicated hosting plan which provides more resources. However, if that isn't an option, reducing the amount of data being retrieved should be explored.

    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.