question

VladMenshchAdmin-6329 avatar image
0 Votes"
VladMenshchAdmin-6329 asked VladMenshchAdmin-6329 published

Az Function App App files -requirements.psd1

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VladMenshchAdmin-6329 avatar image
0 Votes"
VladMenshchAdmin-6329 answered

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'
}

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT edited

@VladMenshchAdmin-6329 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.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Host,json is already set to true

{
"version": "2.0",
"managedDependency": {
"Enabled": true
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}

I tired folowing this https://tech.nicolonsky.ch/azure-functions-powershell-modules/ but I can't find MSAL.PS on my PC.

0 Votes 0 ·
VladMenshchAdmin-6329 avatar image VladMenshchAdmin-6329 VladMenshchAdmin-6329 ·

Also, I created folder Module and copied AZ.storage fold from My PC. I am still getting the same error131653-2021-09-13-10-50-59.png


0 Votes 0 ·
MayankBargali-MSFT avatar image MayankBargali-MSFT VladMenshchAdmin-6329 ·

@VladMenshchAdmin-6329 Can you please confirm if you have redeploy your application again post uncommenting # 'Az' = '6.*' in your requirements.psd1 file as mentioned previously.

 @{
 # 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.*'
 }
0 Votes 0 ·
VladMenshchAdmin-6329 avatar image
0 Votes"
VladMenshchAdmin-6329 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VladMenshchAdmin-6329 avatar image
0 Votes"
VladMenshchAdmin-6329 answered VladMenshchAdmin-6329 published

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I cleared the log and started the test again. Timer is set to run once a day.

2021-09-14T22:34:14.821 [Information] Executing 'Functions.TimerTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=f8988796-5082-441e-8409-fb7b2fab86b1)
2021-09-14T22:34:34.609 [Information] Executed 'Functions.TimerTrigger1' (Succeeded, Id=f8988796-5082-441e-8409-fb7b2fab86b1, Duration=19795ms)
2021-09-14T22:36:25 No new trace in the past 1 min(s).
2021-09-14T22:37:25 No new trace in the past 2 min(s).
2021-09-14T22:38:25 No new trace in the past 3 min(s).
2021-09-14T22:39:25 No new trace in the past 4 min(s).
2021-09-14T22:40:25 No new trace in the past 5 min(s).
2021-09-14T22:41:25 No new trace in the past 6 min(s).
2021-09-14T22:42:25 No new trace in the past 7 min(s).
2021-09-14T22:43:25 No new trace in the past 8 min(s).
2021-09-14T22:44:25 No new trace in the past 9 min(s).
2021-09-14T22:45:25 No new trace in the past 10 min(s).
2021-09-14T22:46:25 No new trace in the past 11 min(s).
2021-09-14T22:47:25 No new trace in the past 12 min(s).
2021-09-14T22:48:25 No new trace in the past 13 min(s).
2021-09-14T22:49:25 No new trace in the past 14 min(s).

0 Votes 0 ·