Azure Functions Flex consumption plan bicep code deployment
Hello, i try to deploy an azure function with its code using bicep template.
the problem is that i got 404 error when try to deploy using onedeploy.
after some investigation, it is look like that, when the bicep deploy it remove all deployment logs includes the logs of the current new code deployment and then the arm deployment got an 404 error.
when i look at the function deployment logs and refresh it i found this error before the log is disappear and the 404 error raised at the arm deployment:
"The logs you are looking for were not found. In consumption plans, the instance will be recycled and logs will not be persisted after that. If you want them to be persisted ensure that Application Insights is enabled. See the Deployment Logs section here for more info: https://aka.ms/flex-deployments " ( the link is broken... )
an example bicep:
(the function blob container is already created when the storage account was created )
param location string = 'northeurope'
param name string = '<func-name>'
param storageAccountName string = '<my-storage>'
param artifactBlobName string = '<blob-name-in-storage>'
param subnetId string = '<subnet-id>'
resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = {
name: 'sp-${name}'
location: location
sku: {
name: 'FC1'
tier: 'FlexConsumption'
capacity: 2
}
kind: 'functionapp,linux'
properties: {
reserved: true
}
}
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
name: 'workspace-${name}'
location: location
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: 'insights-${name}'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalytics.id
}
}
// Reference the existing storage account (used for code artifact storage)
resource functionsStorageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
name: storageAccountName
}
resource functionApp 'Microsoft.Web/sites@2024-04-01' = {
name: name
location: location
kind: 'functionapp,linux'
identity: { type: 'SystemAssigned' }
properties: {
httpsOnly: true
publicNetworkAccess: 'Enabled'
reserved: true
vnetRouteAllEnabled: true
serverFarmId: appServicePlan.id
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage__accountName'
value: storageAccountName
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: applicationInsights.properties.ConnectionString
}
]
}
functionAppConfig: {
scaleAndConcurrency: {
maximumInstanceCount: 100
instanceMemoryMB: 2048
alwaysReady: []
}
runtime: { name: 'node', version: '20' }
deployment: {
storage: {
type: 'blobContainer'
value: 'https://${storageAccountName}.blob.${environment().suffixes.storage}/${name}'
authentication: {
type: 'SystemAssignedIdentity'
}
}
}
}
virtualNetworkSubnetId: subnetId
}
}
param deployTime string = utcNow('u')
// Generate a SAS token for the artifact blob (valid for 1 hour)
var serviceSasToken = functionsStorageAccount.listServiceSas(functionsStorageAccount.apiVersion, {
signedResource: 'b'
signedPermission: 'rl'
// The canonicalized resource should be in the format: /blob/<storageAccount>/<container>/<blob>
canonicalizedResource: '/blob/${storageAccountName}/artifacts/${artifactBlobName}'
signedExpiry: dateTimeAdd(deployTime, 'PT1H')
}).serviceSasToken
// Build the full artifact URL including the SAS token and a query parameter to force a change
var artifactUrl = 'https://${storageAccountName}.blob.${environment().suffixes.storage}/artifacts/${artifactBlobName}?${serviceSasToken}'
// Deploy the OneDeploy extension to the Function App
resource functionOneDeploy 'Microsoft.Web/sites/extensions@2024-04-01' = {
parent: functionApp
name: 'onedeploy'
properties: {
packageUri: artifactUrl
remoteBuild: false
}
}