Az Function App App files -requirements.psd1

VladAdmin 146 Reputation points
2021-09-09T20:08:00.86+00:00

Trying to use this script in the Function App and I am getting an error The Function app may be missing a module containing the 'New-AzStorageContext' command definition. If this command belongs to a module available on the PowerShell Gallery, add a reference to this module to requirements.psd1.

This script works in my PowerShell no problem

$CleanupTime = [DateTime]::UtcNow.AddHours(-1440)
$context = New-AzStorageContext -StorageAccountName masteryeducation1433 -StorageAccountKey "mykey"
Get-AzStorageBlob -Container "sql-db-full-backups-mul" -Context $context |
Where-Object { $.LastModified.UtcDateTime -lt $CleanupTime -and $.BlobType -eq "PageBlob" -and $_.Name -like "*.bak"} |
Remove-AzStorageBlob

my requirements.psd1

@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
# 'Az' = '6.*'
}

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,321 questions
0 comments No comments
{count} votes

Accepted answer
  1. VladAdmin 146 Reputation points
    2021-09-14T22:26:58.68+00:00

    I had incorrect parameter. I got it to work with below parameter.

    @{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
    # To use the Az module in your function app, please uncomment the line below.
    'Az' = '6.*'
    'Az.Storage' = '3.11.0'
    }

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. MayankBargali-MSFT 68,746 Reputation points
    2021-09-10T05:53:33.963+00:00

    @VladAdmin As per requirements.psd1 you have commented # 'Az' = '6.*'
    Please uncomment it and redeploy your function app. Please make sure that you have also set managedDependency to true in the root of host.json file. As there is no Az module install on your function the error is expected behaviour. Your New-AzStorageContext command is the part of Az.Storage module and Az module does install these Dependencies.
    Please refer to Dependency management section for more details.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


  2. VladAdmin 146 Reputation points
    2021-09-14T20:20:13.69+00:00

    I went to kudo and changed the last row

    This file enables modules to be automatically managed by the Functions service.

    See https://aka.ms/functionsmanageddependency for additional information.

    @{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
    # To use the Az module in your function app, please uncomment the line below.
    # 'Az.Storage' = '3.11.0'
    }

    Then I went to Function App and created a new App. Then created a new Function TimerTriger and I am still getting the same error.

    0 comments No comments

  3. VladAdmin 146 Reputation points
    2021-09-14T22:28:33.423+00:00

    Now I am getting No new trace in the past xx minutes. What does it mean?

    2021-09-14T21:53:25 Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds).
    2021-09-14T21:53:24.577 [Information] Executing 'Functions.TimerTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=d547cee3-773c-4d98-b720-3d6108e7bd48)
    2021-09-14T21:53:24.597 [Warning] The first managed dependency download is in progress, function execution will continue when it's done. Depending on the content of requirements.psd1, this can take a few minutes. Subsequent function executions will not block and updates will be performed in the background.
    2021-09-14T21:55:25 No new trace in the past 1 min(s).
    2021-09-14T21:56:25 No new trace in the past 2 min(s).
    2021-09-14T21:56:33.724 [Error] Timeout value of 00:05:00 exceeded by function 'Functions.TimerTrigger1' (Id: '3a11e1cb-b8bf-4641-b395-267c91ef037e'). Initiating cancellation.
    2021-09-14T21:58:24.623 [Error] Timeout value of 00:05:00 exceeded by function 'Functions.TimerTrigger1' (Id: 'd547cee3-773c-4d98-b720-3d6108e7bd48'). Initiating cancellation.
    2021-09-14T21:58:24.714 [Error] Executed 'Functions.TimerTrigger1' (Failed, Id=d547cee3-773c-4d98-b720-3d6108e7bd48, Duration=300112ms)Timeout value of 00:05:00 was exceeded by function: Functions.TimerTrigger1
    2021-09-14T21:59:25 No new trace in the past 1 min(s).
    2021-09-14T22:00:25 No new trace in the past 2 min(s).
    2021-09-14T22:01:25 No new trace in the past 3 min(s).
    2021-09-14T22:02:25 No new trace in the past 4 min(s).
    2021-09-14T22:03:25 No new trace in the past 5 min(s).
    2021-09-14T22:04:25 No new trace in the past 6 min(s).
    2021-09-14T22:05:25 No new trace in the past 7 min(s).
    2021-09-14T22:06:25 No new trace in the past 8 min(s).
    2021-09-14T22:07:25 No new trace in the past 9 min(s).
    2021-09-14T22:08:25 No new trace in the past 10 min(s).
    2021-09-14T22:09:25 No new trace in the past 11 min(s).
    2021-09-14T22:10:25 No new trace in the past 12 min(s).
    2021-09-14T22:11:25 No new trace in the past 13 min(s).
    2021-09-14T22:12:25 No new trace in the past 14 min(s).
    2021-09-14T22:13:25 No new trace in the past 15 min(s).
    2021-09-14T22:14:25 No new trace in the past 16 min(s).
    2021-09-14T22:15:25 No new trace in the past 17 min(s).
    2021-09-14T22:16:25 No new trace in the past 18 min(s).
    2021-09-14T22:17:25 No new trace in the past 19 min(s).
    2021-09-14T22:18:25 No new trace in the past 20 min(s).
    2021-09-14T22:19:25 No new trace in the past 21 min(s).
    2021-09-14T22:20:25 No new trace in the past 22 min(s).
    2021-09-14T22:21:25 No new trace in the past 23 min(s).
    2021-09-14T22:22:25 No new trace in the past 24 min(s).
    2021-09-14T22:23:25 No new trace in the past 25 min(s).
    2021-09-14T22:24:25 No new trace in the past 26 min(s).
    2021-09-14T22:25:25 No new trace in the past 27 min(s).
    2021-09-14T22:26:25 No new trace in the past 28 min(s).
    2021-09-14T22:27:25 No new trace in the past 29 min(s).

    1 person found this answer helpful.