Share via

Azure function deploy error using MSDeploy in Bicep file

Valeria Naldi 145 Reputation points
2023-08-29T15:29:57.2866667+00:00

I'm using a bicep file to deploy Azure resources, among them a FunctionApp and 3 Functions

FunctionApp deployment works fine.

I'm deploying Functions using a zip file created from the "Download app content" button on a previously created FunctionApp and Functions and uploaded on a git repository

This is the bicep content:

resource funcAppDeploy 'Microsoft.Web/sites/extensions@2020-12-01' = {
  parent: funcApp
  name: 'MSDeploy'
  properties: {
    packageUri: funcPackageUri
  }
}

where funcPackageUri is like this

var funcPackageUri = 'https://github.com/<repoorg>/<reponame>/raw/main/<foldername>/funcapp-deploy.zip'

I have this error during the deployment:

{"code":"Failed","message":"ARM-MSDeploy Deploy Failed: 'Microsoft.Web.Deployment.DeploymentDetailedException: Object of type 'package' and path 'C:\local\Temp\f5e1b1e4-1a43-4567-95d7-d4ae670fd17f.zip' cannot be created. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_EXCEPTION_WHILE_CREATING_OBJECT. ---> Microsoft.Web.Deployment.DeploymentException: The Zip package 'C:\local\Temp\f5e1b1e4-1a43-4567-95d7-d4ae670fd17f.zip' could not be loaded. ---> System.IO.EndOfStreamException: Unable to read beyond the end of the stream.\r\n at System.IO.BinaryReader.FillBuffer(Int32 numBytes)\r\n at System.IO.BinaryReader.ReadInt32()\r\n at Microsoft.Web.Deployment.ZipFile.Load()\r\n at Microsoft.Web.Deployment.ZipPackageProvider..ctor(DeploymentProviderContext providerContext, DeploymentBaseContext baseContext, String path)\r\n --- End of inner exception stack trace ---\r\n at Microsoft.Web.Deployment.ZipPackageProvider.GetAttributes(DeploymentAddAttributeContext addContext)\r\n at Microsoft.Web.Deployment.DeploymentObject.EnsureValidAttributes()\r\n --- End of inner exception stack trace ---\r\n at Microsoft.Web.Deployment.DeploymentManager.CreateObjectPrivate(DeploymentProviderContext providerContext, DeploymentBaseOptions baseOptions, DeploymentObject sourceObject, String serverVersion)\r\n at Microsoft.Web.Deployment.DeploymentManager.CreateObject(DeploymentProviderOptions providerOptions, DeploymentBaseOptions baseOptions)\r\n at Microsoft.Web.Deployment.DeploymentManager.CreateObject(String provider, String path, DeploymentBaseOptions baseOptions)\r\n at Microsoft.Web.Deployment.DeploymentManager.CreateObject(DeploymentWellKnownProvider provider, String path, DeploymentBaseOptions baseOptions)\r\n at Microsoft.Web.Deployment.WebApi.AppGalleryPackage.Deploy(String deploymentSite, String siteSlotId, Boolean doNotDelete) in C:\__w\1\s\src\hosting\wdeploy\Microsoft.Web.Deployment.WebApi\AppGalleryPackage.cs:line 250\r\n at Microsoft.Web.Deployment.WebApi.DeploymentController.<DownloadAndDeployPackage>d__25.MoveNext() in C:\__w\1\s\src\hosting\wdeploy\Microsoft.Web.Deployment.WebApi\Controllers\DeploymentController.cs:line 492'"}

Can you please help me to understand what is wrong?

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

0 comments No comments

Answer accepted by question author

Mike Urnun 9,792 Reputation points Moderator
2023-08-29T19:43:08.85+00:00

Hello, @Valeria Naldi - Thanks for reaching out! The error ERROR_EXCEPTION_WHILE_CREATING_OBJECT indicates that the MSDeploy wasn't able to access the zip file hence not being able to recreate it in the C:\local\Temp\f5e1b1e4-1a43-4567-95d7-d4ae670fd17f.zip directory. I suspect that the root cause could be either an access issue when downloading or a permission-related issue on the filesystem. It's also a best practice to set appOffline to true when using MSDeploy.

On another note though, I highly recommend that you move away from MSDeploy and switch to ZipDeploy along with RUN_FROM_PACKAGE app setting instead as this is the official recommendation by the Functions team. Here's the official sample for ARM template with ZipDeploy:

If you're hesitant about using ZipDeplooy, here are some links that might help:

I hope this answer helps. If you have any further questions, feel free to follow up in the comments ;)

Was this answer helpful?


0 additional answers

Sort by: Most helpful

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.