node.jsazure-functionsvscode-extensions

403 Forbidden when deploying a NodeJS Function App


I'm facing this error when trying to deploy a new function in Flexible plan, using VS Code Azure Functions extensions and option "Deploy to Function App". I created the Function App wihtout errors.

In IAM I have Owner role.

17:43:59 flow-metrics-dev-fn: Starting deployment...
17:44:01 flow-metrics-dev-fn: Creating zip package...
17:44:01 flow-metrics-dev-fn: Adding 6 files to zip package...
17:44:01 flow-metrics-dev-fn: azure_blueprint.png
17:44:01 flow-metrics-dev-fn: README.md
17:44:01 flow-metrics-dev-fn: Commons.js.map
17:44:01 flow-metrics-dev-fn: MetricsStorageQueueConsumer.js.map
17:44:01 flow-metrics-dev-fn: Commons.js
17:44:01 flow-metrics-dev-fn: MetricsStorageQueueConsumer.js
17:44:02 flow-metrics-dev-fn: Zip package size: 73.3 kB
17:44:21: Error: Error 403 - Forbidden
The web app you have attempted to reach has blocked your access.

There's a short version of the code, the connection is in local.settings.json

export async function MetricsStorageQueueConsumer(queueItem: unknown, context: InvocationContext): Promise<void> {
    context.log('Storage queue function processed work item:', queueItem);
}

app.storageQueue('MetricsStorageQueueConsumer', {
    queueName: 'my-queue',
    connection: 'AzureWebJobsStorage',
    handler: MetricsStorageQueueConsumer
});

This function already existed in Serverless plan (and Premium for a while), and I was able to deploy using same steps, but last week I started to face the same 403 error, also in Serverless.

Update 1

After enabling all networks in function app, I was able to deploy it.

09:27:54 flow-metrics-dev-fn: Starting deployment...
09:27:57 flow-metrics-dev-fn: Creating zip package...
09:27:57 flow-metrics-dev-fn: Adding 4 files to zip package...
09:27:57 flow-metrics-dev-fn: Commons.js.map
09:27:57 flow-metrics-dev-fn: MetricsStorageQueueConsumer.js.map
09:27:57 flow-metrics-dev-fn: Commons.js
09:27:57 flow-metrics-dev-fn: MetricsStorageQueueConsumer.js
09:27:57 flow-metrics-dev-fn: Zip package size: 73.3 kB
09:28:01 flow-metrics-dev-fn: Starting deployment pipeline.
09:28:01 flow-metrics-dev-fn: [ValidationStep] starting.
09:28:01 flow-metrics-dev-fn: [AppSettingValidation] starting.
09:28:01 flow-metrics-dev-fn: [DeploymentStorageValidation] starting.
09:28:01 flow-metrics-dev-fn: Validation completed
09:28:01 flow-metrics-dev-fn: [SourcePackageUriDownloadStep] starting.
09:28:01 flow-metrics-dev-fn: Zip package is present at /tmp/zipdeploy/79ade4bc-e88d-41f1-87bb-a8c90253e511.zip
09:28:01 flow-metrics-dev-fn: [ExtractZipStep] starting.
09:28:01 flow-metrics-dev-fn: Cleaning files in /tmp/zipdeploy/extracted
09:28:01 flow-metrics-dev-fn: Extracted zip package in /tmp/zipdeploy/extracted
09:28:01 flow-metrics-dev-fn: [OryxBuildStep] starting.
09:28:01 flow-metrics-dev-fn: Skipping oryx build (remotebuild = false).
09:28:01 flow-metrics-dev-fn: [PackageZipStep] starting.
09:28:01 flow-metrics-dev-fn: Linux Consumption plan has a 1.5 GB memory limit on a remote build container. To check our service limit, please visit https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#service-limits
09:28:01 flow-metrics-dev-fn: Created zip file with artifacts as /home/site/artifacts/79ade4bc-e88d-41f1-87bb-a8c90253e511.zip.
09:28:01 flow-metrics-dev-fn: [UploadPackageStep] starting.
09:28:01 flow-metrics-dev-fn: Using Kudu.Legion.Core.Storage.BlobContainerStorage
09:28:01 flow-metrics-dev-fn: Created blob name: released-package.zip
09:28:01 flow-metrics-dev-fn: Created blob uri: https://flowmetricsdevsa.blob.core.windows.net/app-package-flow-metrics-dev-fn-ec98950/released-package.zip
09:28:01 flow-metrics-dev-fn: Created Storage Credentials using storage account connection string
09:28:02 flow-metrics-dev-fn: Uploaded blob successfully.
09:28:02 flow-metrics-dev-fn: Uploaded package to storage blob. Deployment is partially successful from here.
09:28:02 flow-metrics-dev-fn: [RemoveWorkersStep] starting.
09:28:02 flow-metrics-dev-fn: RemoveAllWorkers, statusCode = NoContent
09:28:02 flow-metrics-dev-fn: Reset all workers was successful.
09:28:02 flow-metrics-dev-fn: [SyncTriggerStep] starting.
09:28:02 flow-metrics-dev-fn: Waiting 60 seconds for the workers to recycle with deployed content.
09:29:02 flow-metrics-dev-fn: [CleanUpStep] starting.
09:29:02 flow-metrics-dev-fn: Cleaned the source packages directory.
09:29:02 flow-metrics-dev-fn: Cleaned the result artifact directory.
09:29:02 flow-metrics-dev-fn: Finished deployment pipeline.
09:29:02 flow-metrics-dev-fn: FunctionHostSyncTrigger, statusCode = Moved
09:29:04 flow-metrics-dev-fn: FunctionHostSyncTrigger, statusCode = Moved
09:29:05 flow-metrics-dev-fn: Started postDeployTask "npm install (functions)".
09:29:06 flow-metrics-dev-fn: Querying triggers...
09:30:26 flow-metrics-dev-fn: No HTTP triggers found.

But it's still not visible in Azure Function App Overview Page

Update 2

19/06/2024, 19:55:32.581
Call to StopAsync complete, registered listeners are now stopped
19/06/2024, 19:55:32.580
Calling StopAsync on the registered listeners
19/06/2024, 19:55:32.580
DrainMode mode enabled
19/06/2024, 19:55:26.576
Host lock lease acquired by instance ID '000000000000000000000000B8539C2A'.
19/06/2024, 19:55:26.313
Host Status: { "id": "a9006d3e7b2732f63741d3691fff9e0c", "state": "Running", "version": "4.1033.10.10", "versionDetails": "4.1033.10+464d39357ca9e6138c6506649359e25e5f28e89a", "platformVersion": "", "instanceId": "cf23cd70-396f-44c3-898a-c288a146a5c3", "computerName": "", "processUptime": 19280641, "functionAppContentEditingState": "NotAllowed" }
19/06/2024, 19:55:26.096
Host Status: { "id": "a9006d3e7b2732f63741d3691fff9e0c", "state": "Running", "version": "4.1033.10.10", "versionDetails": "4.1033.10+464d39357ca9e6138c6506649359e25e5f28e89a", "platformVersion": "", "instanceId": "cf23cd70-396f-44c3-898a-c288a146a5c3", "computerName": "", "processUptime": 19280425, "functionAppContentEditingState": "NotAllowed" }
19/06/2024, 19:55:21.481
Host Status: { "id": "a9006d3e7b2732f63741d3691fff9e0c", "state": "Running", "version": "4.1033.10.10", "versionDetails": "4.1033.10+464d39357ca9e6138c6506649359e25e5f28e89a", "platformVersion": "", "instanceId": "cf23cd70-396f-44c3-898a-c288a146a5c3", "computerName": "", "processUptime": 19275810, "functionAppContentEditingState": "NotAllowed" }
19/06/2024, 19:55:21.472
Job host started
19/06/2024, 19:55:21.472
Host started (6ms)
19/06/2024, 19:55:21.472
Host initialized (6ms)
19/06/2024, 19:55:21.472
Initializing function HTTP routes No HTTP routes mapped
19/06/2024, 19:55:21.472
HttpOptions { "DynamicThrottlesEnabled": false, "EnableChunkedRequestBinding": false, "MaxConcurrentRequests": -1, "MaxOutstandingRequests": -1, "RoutePrefix": "api" }
19/06/2024, 19:55:21.471
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
19/06/2024, 19:55:21.470
Generating 0 job function(s)
19/06/2024, 19:55:21.469
0 functions loaded
19/06/2024, 19:55:21.469
1 functions found (Custom)
19/06/2024, 19:55:21.469
Reading functions metadata (Custom)
19/06/2024, 19:55:21.466
Loading functions metadata
19/06/2024, 19:55:21.466
Starting Host (HostId=a9006d3e7b2732f63741d3691fff9e0c, InstanceId=f28fc530-76ee-4b2c-bbd5-5185e80cdd81, Version=4.1033.10.10, ProcessId=34, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=~1)
19/06/2024, 19:55:21.465
Starting JobHost
19/06/2024, 19:55:21.459
Initializing Host. OperationId: '84859c2f-7584-4a0c-add9-e991626adca6'.

Solution

  • Make sure you don't have access restrictions enabled under Networking in the function app and Storage Account. Enable Public Network Access from all networks.

    Function App:

    enter image description here

    Storage Account:

    enter image description here

    I have created a NodeJS Azure function App and could deploy your code.

    function.ts:

    import { app, InvocationContext } from "@azure/functions";
    
    export async function MetricsStorageQueueConsumer(queueItem: unknown, context: InvocationContext): Promise<void> {
        context.log('Storage queue function processed work item:', queueItem);
    }
    
    app.storageQueue('MetricsStorageQueueConsumer', {
        queueName: 'js-queue-items',
        connection: 'AzureWebJobsStorage',
        handler: MetricsStorageQueueConsumer
    });
    
    C:\Users\uname\nodefn>npm start
    
    > prestart
    > npm run clean && npm run build
    
    > clean
    > rimraf dist
    
    > build
    > tsc
    
    > start
    > func start
    
    Azure Functions Core Tools
    Core Tools Version:       4.0.5801 Commit hash: N/A +5ac2f09758b9XXXXX5576ce5ea9ef68ff (64-bit)
    Function Runtime Version: 4.34.1.22669
    
    [2024-06-07T06:41:10.743Z] Worker process started and initialized.
    
    Functions:
            MetricsStorageQueueConsumer: queueTrigger
    
    For detailed output, run func with --verbose flag.
    [2024-06-07T06:41:17.303Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.
    [2024-06-07T06:41:19.699Z] Executing 'Functions.MetricsStorageQueueConsumer' (Reason='New queue message detected on 'js-queue-items'.', Id=20b7085b-3891-4936-8853-dd33f554e779)
    [2024-06-07T06:41:19.704Z] Trigger Details: MessageId: 514648fa-64c0-4032-9beb-c29475b7115f, DequeueCount: 1, InsertedOn: 2024-06-07T06:41:18.000+00:00
    [2024-06-07T06:41:19.767Z] Storage queue function processed work item: Hello World
    [2024-06-07T06:41:19.789Z] Executed 'Functions.MetricsStorageQueueConsumer' (Succeeded, Id=20b7085b-3891-4936-8853-dd33f554e779, Duration=113ms)
    

    Output Logs:

    12:33:21 PM kpnodefn: Starting deployment...
    12:33:21 PM kpnodefn: Creating zip package...
    12:33:22 PM kpnodefn: Adding 275 files to zip package...
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\host.json
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\.funcignore
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\node_modules\.package-lock.json
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\dist\src\functions\MetricsStorageQueueConsumer.js.map
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\dist\src\functions\MetricsStorageQueueConsumer.js
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\node_modules\undici\index.js
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\node_modules\undici\LICENSE
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\node_modules\undici\types\README.md
    12:33:22 PM kpnodefn: c:\Users\uname\nodefn\package.json
    //Removed few logs
    12:33:22 PM kpnodefn: c:\Users\v-pkothaveer\nodefn\node_modules\undici\docs\api\Dispatcher.md
    //Removed few logs
    12:33:22 PM kpnodefn: c:\Users\v-pkothaveer\nodefn\package-lock.json
    //Removed few logs
    12:33:22 PM kpnodefn: c:\Users\v-pkothaveer\nodefn\tsconfig.json
    12:33:22 PM kpnodefn: c:\Users\v-pkothaveer\nodefn\node_modules\@fastify\busboy\lib\utils\basename.js
    //Removed few logs
    12:33:22 PM kpnodefn: c:\Users\v-pkothaveer\nodefn\node_modules\@azure\functions\src\output.ts
    //Removed few logs
    12:33:28 PM kpnodefn: Zip package size: 658 kB
    12:33:30 PM kpnodefn: Updating submodules.
    12:33:30 PM kpnodefn: Preparing deployment for commit id '51e1543725'.
    12:33:31 PM kpnodefn: Skipping build. Project type: Run-From-Zip
    12:33:31 PM kpnodefn: Skipping post build. Project type: Run-From-Zip
    12:33:31 PM kpnodefn: Triggering recycle (preview mode disabled).
    12:33:32 PM kpnodefn: Deployment successful.
    12:33:34 PM kpnodefn: Started postDeployTask "npm install (functions)".
    12:33:45 PM kpnodefn: Syncing triggers...
    12:33:51 PM kpnodefn: Querying triggers...
    12:33:57 PM kpnodefn: No HTTP triggers found.
    

    Portal:

    enter image description here

    Invocations:

    enter image description here