Using blobTrigger with Azurite crashes function host - azure

I'm running into a problem with a Azure blob triggered function crashing the function host. It seems to be an issue with the storage connection string or how I'm using Azurite. Other timer or HTTP trigger functions I'm working on work fine with the "UseDevelopmentStorage=true" setting and the Azurite blob service running.
I'm rather stumped as to what the issue could be with getting a blob trigger function to work in my dev environment using the Azurite storage emulator.
Any suggests about what I'm missing or where to look futher?
This is the error message I get about 10 to 20 seconds after the function host starts:
An unhandled exception has occurred. Host is shutting down.
Microsoft.WindowsAzure.Storage: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.
The function.json file for the blob trigger function looks like this:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "outcontainer/{name}",
"connection": "AzureWebJobsStorage"
}
]
}
The local.settings.json file has this:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
This is the output from console with the --verbose switch enabled:
[9/23/2020 6:28:36 PM] Job host started
Functions:
BlobTrigger1: blobTrigger
Hosting environment: Production
Content root path: C:\sources\AzureBlobTriggerTest
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[9/23/2020 6:28:37 PM] LanguageWorkerConsoleLog INFO: Starting Azure Functions Python Worker.
[9/23/2020 6:28:37 PM] LanguageWorkerConsoleLog INFO: Worker ID: d4160c17-a9f0-461d-af04-18623c45a51b, Request ID: fdf8841e-8564-4f4e-a983-91553451cd9d, Host Address: 127.0.0.1:51168
[9/23/2020 6:28:37 PM] LanguageWorkerConsoleLog INFO: Successfully opened gRPC channel to 127.0.0.1:51168
[9/23/2020 6:28:37 PM] LanguageWorkerConsoleLog INFO: Detaching console logging.
[9/23/2020 6:28:37 PM] Switched to gRPC logging.
[9/23/2020 6:28:37 PM] Received WorkerInitRequest, request ID fdf8841e-8564-4f4e-a983-91553451cd9d
[9/23/2020 6:28:37 PM] Worker process started and initialized.
[9/23/2020 6:28:37 PM] Received FunctionLoadRequest, request ID: fdf8841e-8564-4f4e-a983-91553451cd9d, function ID: dc522140-aa0a-453b-8767-4aedf88435e4
[9/23/2020 6:28:37 PM] Successfully processed FunctionLoadRequest, request ID: fdf8841e-8564-4f4e-a983-91553451cd9d, function ID: dc522140-aa0a-453b-8767-4aedf88435e4
[9/23/2020 6:28:41 PM] Host lock lease acquired by instance ID '0000000000000000000000002B956994'.
[9/23/2020 6:29:09 PM] An unhandled exception has occurred. Host is shutting down.
[9/23/2020 6:29:09 PM] Microsoft.WindowsAzure.Storage: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.
[9/23/2020 6:29:09 PM] Stopping host...
[9/23/2020 6:29:09 PM] Stopping JobHost
[9/23/2020 6:29:09 PM] Stopping the listener 'Microsoft.Azure.WebJobs.Host.Listeners.CompositeListener' for function 'BlobTrigger1'
[9/23/2020 6:29:09 PM] Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.CompositeListener' for function 'BlobTrigger1'
[9/23/2020 6:29:09 PM] Job host stopped
[9/23/2020 6:29:09 PM] Host shutdown completed.

Looks like I found what I was doing wrong. The documentation says, "The Azure Blob storage trigger requires a general-purpose storage account."
I was only starting the Azurite blob service. Starting the whole thing gets it working.

To run a Node blobTrigger locally you need to:
Make sure you are running Node 8 or 10. I run 10.14.1
Change local.settings.json:
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
Run azurite with all services. Not only BlobStorage.

Related

CloudQueueMessage QueueTrigger in Azure vs Local Instance

I need to be able to get to the queue item itself (not the string), so that I can manipulate it from my function.
In run.csx code blelow runs and i get access to CloudQueueMessage
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Queue;
using System;
public static void Run(CloudQueueMessage myQueueItem, ILogger log)
{
log.LogInformation($"Queue ID: {myQueueItem.Id}");
log.LogInformation($"Queue Insertion Time: {myQueueItem.InsertionTime}");
log.LogInformation($"Queue Expiration Time: {myQueueItem.ExpirationTime}");
log.LogInformation($"Queue Payload: {myQueueItem.AsString}");
}
In my local development this code throws an error.
I use all latest Nuget's.
VS2017 15.8.8
Azure Function and Web Job Tools: 15.10.2046.0
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Queue;
namespace AzurePumps.MyForce
{
public static class PersonQueueProcessor
{
[FunctionName("PersonQueueProcessor")]
public static void Run([QueueTrigger("sfcontact-update-error", Connection = "storage-queue-connection")]CloudQueueMessage myQueueItem, ILogger log)
{
log.LogInformation($"Queue ID: {myQueueItem.Id}");
log.LogInformation($"Queue Insertion Time: {myQueueItem.InsertionTime}");
log.LogInformation($"Queue Expiration Time: {myQueueItem.ExpirationTime}");
log.LogInformation($"Queue Payload: {myQueueItem.AsString}");
}
}
}
Log:
Azure Functions Core Tools (2.1.748 Commit hash: 5db20665cf0c11bedaffc96d81c9baef7456acb3)
Function Runtime Version: 2.0.12134.0
Skipping 'SF_SecurityToken' from local settings as it's already defined in current environment variables.
[10/26/2018 8:07:51 PM] Building host: startup suppressed:False, configuration suppressed: False
[10/26/2018 8:07:52 PM] Reading host configuration file 'D:\Projects\Force\bin\Debug\netstandard2.0\host.json'
[10/26/2018 8:07:52 PM] Host configuration file read:
[10/26/2018 8:07:52 PM] {
[10/26/2018 8:07:52 PM] "version": "2.0"
[10/26/2018 8:07:52 PM] }
[10/26/2018 8:07:53 PM] Initializing Host.
[10/26/2018 8:07:53 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1
[10/26/2018 8:07:53 PM] Starting JobHost
[10/26/2018 8:07:53 PM] Starting Host (HostId=vddk35x1fmsnlt-1608145051, InstanceId=e9842cc2-f4a1-46c2-80d0-3e0aad9ae83b, Version=2.0.12134.0, ProcessId=16720, AppDomainId=1, Debug=False, FunctionsExtensionVersion=)
[10/26/2018 8:07:53 PM] Loading functions metadata
[10/26/2018 8:07:53 PM] 2 functions loaded
[10/26/2018 8:07:54 PM] Generating 2 job function(s)
[10/26/2018 8:07:55 PM] Found the following functions:
[10/26/2018 8:07:55 PM] AzurePumps.MyForce.PersonProcessor.Run
[10/26/2018 8:07:55 PM] AzurePumps.MyForce.PersonQueueProcessor.Run
[10/26/2018 8:07:55 PM]
[10/26/2018 8:07:55 PM] Host initialized (1859ms)
[10/26/2018 8:08:00 PM] Host started (6876ms)
[10/26/2018 8:08:00 PM] Job host started
Hosting environment: Production
Content root path: D:\Projects\Force\bin\Debug\netstandard2.0
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Listening on http://0.0.0.0:7071/
Hit CTRL-C to exit...
[10/26/2018 8:08:06 PM] Host lock lease acquired by instance ID '0000000000000000000000006DB263D8'.
[10/26/2018 8:08:22 PM] Executing 'PersonQueueProcessor' (Reason='New queue message detected on 'sfcontact-update-error'.', Id=1e37d3a4-a992-41c8-b6ca-595787e5224e)
[10/26/2018 8:08:23 PM] Executed 'PersonQueueProcessor' (Failed, Id=1e37d3a4-a992-41c8-b6ca-595787e5224e)
**[10/26/2018 8:08:23 PM] System.Private.CoreLib: Exception while executing function: PersonQueueProcessor. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'myQueueItem'. Microsoft.Azure.WebJobs.Extensions.Storage: Binding parameters to complex objects (such as 'CloudQueueMessage') uses Json.NET serialization.
1. Bind the parameter type as 'string' instead of 'CloudQueueMessage' to get the raw values and avoid JSON deserialization, or
2. Change the queue payload to be valid json. The JSON parser failed: Unexpected character encountered while parsing value: i. Path '', line 0, position 0.**
Make sure you don't reference/install WindowsAzure.Storage latest version 9.3.2, there seems a bug when integrating with Function SDK. See the issue tracked.
Right now when we create a v2 Function Project, the dependencies in the template, e.g. Microsoft.NET.SDK.Functions references WindowsAzure.Storage 9.3.1 by default. This version works well(as you have seen in Azure portal), no need to install the package separately.
Besides, recommend you to update Microsoft.Azure.WebJobs.Extensions.Storage to 3.0.1 to avoid some first chance exception throwing.

Azure function v2. Cannot reference dll from nuget

I am testing how to write a simple azure function that updates an azure sql database.
From VS2017 I made a new Cloud->Azure function v2 with netstandars 2.0. My code is the following:
[FunctionName("Activate")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequest req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string serialNumber = req.Query["SerialNumber"];
try
{
var str = "CONNECTION_STRING_FOR AZURE SQL";
using (SqlConnection conn = new SqlConnection(str))
{
conn.Open();
var text = $"UPDATE CLIENT SET ACTIVATION_DATE = '2018-07-23 WHERE SERIAL_NUMBER='{serialNumber}'";
using (SqlCommand cmd = new SqlCommand(text, conn))
{
// Execute the command and log the # rows affected.
var rows = cmd.ExecuteNonQuery();
log.Info($"{rows} rows were updated");
}
}
}
catch (Exception ex)
{
return new BadRequestObjectResult(ex.Message);
}
return serialNumber != null
? (ActionResult)new OkObjectResult($"Hello, {serialNumber}")
: new BadRequestObjectResult("error");
}
It compiles and can be run locally from visual studio:
Hosting environment: Production
Content root path: C:\Projects\xxx\bin\Debug\netstandard2.0
Now listening on: http://localhost:7071
Application started. Press Ctrl+C to shut down.
[24/7/2018 8:50:48 πμ] Reading host configuration file 'C:\Projects\xxx\bin\Debug\netstandard2.0\host.json'
[24/7/2018 8:50:48 πμ] Host configuration file read:
[24/7/2018 8:50:48 πμ] {}
[24/7/2018 8:50:48 πμ] Starting Host (HostId=xxx-1133968365, InstanceId=58079dab-xxx-4bb9-aaf5-f24xxx63d3c, Version=2.0.11651.0, ProcessId=11304, AppDomainId=1, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)
[24/7/2018 8:50:48 πμ] Unable to configure java worker. Could not find JAVA_HOME app setting.
[24/7/2018 8:50:48 πμ]
[24/7/2018 8:50:48 πμ] Could not configure language worker Java.
[24/7/2018 8:50:48 πμ]
[24/7/2018 8:50:49 πμ] Generating 1 job function(s)
[24/7/2018 8:50:49 πμ] Found the following functions:
[24/7/2018 8:50:49 πμ] ClientFunctions.Run
[24/7/2018 8:50:49 πμ]
[24/7/2018 8:50:49 πμ] Host initialized (1511ms)
[24/7/2018 8:50:49 πμ] Host started (1616ms)
[24/7/2018 8:50:49 πμ] Job host started
Listening on http://localhost:7071/
Hit CTRL-C to exit...
Http Functions:
Activate: http://localhost:7071/api/Activate
But if I access it through postman I get:
[24/7/2018 8:52:58 πμ] Executing 'Activate' (Reason='This function was programmatically called via the host APIs.', Id=30cff68d-b8db-446e-bd6d-407990524198)
[24/7/2018 8:52:58 πμ] Executed 'Activate' (Failed, Id=30cff68d-b8db-446e-bd6d-407990524198)
[24/7/2018 8:52:58 πμ] System.Private.CoreLib: Exception while executing function: Activate. Mik3UpdateFunctionNew: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'System.Data.SqlClient, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
What I find strange is that each time I start VS2017 and debug the program, a window appears that says downloading azure functions cli tools 2.3.2.
Can someone suggest anything?
Thanks
#Josh is right. The downloading tip you saw means VS tried to download the latest functin CLI. But actually the downloading failed and it fell back to use the old one, as you can see in your CLI output
Starting Host (...,Version=2.0.11651.0,...)
It represents the function host version, which is used by CLI 2.0.1-beta.25. While for now the latest host is 2.0.11933.0 with CLI 2.0.1-beta.33, i.e.2.3.2 specified by VS.
Here are some details about how to consume the latest CLI.
If you already has the tools folder %LocalAPPDATA%\AzureFunctionsTools, delete it to avoid corrupting new tools.
On VS menus, Tools->Extensions and Updates, find Azure Functions and Web Jobs Tools, make sure it's updated to latest version(right now 15.0.40617.0).
If it has been the latest, just restart VS and create a new Azure Function project, wait at the create dialog for VS to download new CLI and templates.
After a while, we can see the tip change to
Then you can see Starting Host (...,Version=2.0.11933.0,...) while debugging locally and your code should work.
If you still see 2.0.11651.0, go check whether this folder%LocalAPPDATA%\AzureFunctionsTools\Releases\2.3.2exists, which contains cli, templates and manifest.json. If the downloading turns out failed, just delete %LocalAPPDATA%\AzureFunctionsTools folder and restart VS to download again.
Update--how to download tools manually due to poor network.
Open %LocalAPPDATA%\AzureFunctionsTools\feed.json, find "2.3.2":{...} content. Download its cli, itemTemplates and projectTemplates.(Need to rename manually after download).
And folder structure in %LocalAPPDATA%\AzureFunctionsTools\Releases\2.3.2 is like this(same to 2.0.1-beta.25 folder)
cli
--...
templates
--ItemTemplates.nupkg
--ProjectTemplates.nupkg
manifest.json
Content of manifest.json
{
"ReleaseName": "2.3.2",
"CliEntrypointPath":"C:\\Users\\UserName\\AppData\\Local\\AzureFunctionsTools\\Releases\\2.3.2\\cli\\func.exe",
"TemplatesDirectory": "C:\\Users\\UserName\\AppData\\Local\\AzureFunctionsTools\\Releases\\2.3.2\\templates",
"FunctionsExtensionVersion": "beta",
"SdkPackageVersion": "1.0.14"
}
The prompt you are seeing is the Azure Functions extensions for Visual Studio updating your local Azure Functions CLI to the latest version. There has been a lot of updates recently with the Azure Functions 2.0 preview, especially with how assemblies are being resolved (which falls into the category of your error). I would encourage you to allow the update to complete. With all the changes occurring as of late with 2.0 it's easy to get some mismatched versions and references between local dev and whats deployed to azure that causes various problems.
If the error still occurs I would suggest opening an issue on Github with the error details as they are looking for feedback in regards to any assembly binding errors that folks are still getting.

VS 2017 for Mac Azure Function Unable to configure java worker. Could not find JAVA_HOME app setting

I am in the process of creating an Azure Function Apps project. I get
the following error when running the server.
Hosting environment: Production
Content root path:
/Users/dentonsavage/Projects/AzureFunctionTest/AzureFunctionTest/bin/Debug/netstandard2.0
Now listening on: http://localhost:7071 Application started. Press Ctrl+C to shut down.
[7/9/18 9:48:39 PM] Reading host configuration file '/Users/dentonsavage/Projects/AzureFunctionTest/AzureFunctionTest/bin/Debug/netstandard2.0/host.json'
[7/9/18 9:48:39 PM] Host configuration file read:{}
[7/9/18 9:48:39 PM] Starting Host (HostId=shoufu-1532713004, InstanceId=9869d715-4618-48f0-b0d1-16c4fea66dba, Version=2.0.11651.0, ProcessId=43170, AppDomainId=1, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)
[7/9/18 9:48:40 PM] Unable to configure java worker. Could not find JAVA_HOME app setting.
[7/9/18 9:48:40 PM] Could not configure language worker Java.
[7/9/18 9:48:41 PM] Generating 1 job function(s)
[7/9/18 9:48:41 PM] Found the following functions:
[7/9/18 9:48:41 PM] AzureFunctionTest.HttpTrigger.Run
[7/9/18 9:48:41 PM] Host initialized (2120ms) Listening on
http://localhost:7071/ Hit CTRL-C to exit...
Http Functions:
HttpTrigger: http://localhost:7071/api/HttpTrigger
[7/9/18 9:48:43 PM] Host started (3920ms)
[7/9/18 9:48:43 PM] Job host started
[7/9/18 9:48:44 PM] Host lock lease acquired by instance ID '000000000000000000000000C475F100'.
Does anyone know how I can solve this issue? Thank you.
Actually it's not an error. It's just a tip reminding us there's no JAVA_HOME configuration in your system environment variables.
It was used for java development before but has been proved unnecessary and removed in new version Azure Function core tools. See this issue.
So you can just ignore this harmless tip or install latest version function core tools to get rid of it.
Installation Steps:
Install .NET Core for macOS.
Install Homebrew, if it's not already installed.
Install the Core Tools package using bash:
brew tap azure/functions
brew install azure-functions-core-tools
After that navigate to Content root path:
/Users/dentonsavage/Projects/AzureFunctionTest/AzureFunctionTest/bin/Debug/netstandard2.0
Then input func start in bash to debug your project.

Azure Function: Microsoft.WindowsAzure.Storage assembly not found

[15/03/2018 11:03:14 PM] Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=8.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
[15/03/2018 11:03:14 PM] at Tux.Workers.RollCall.Azure.AzureTable.<Init>d__1.MoveNext()
[15/03/2018 11:03:14 PM] at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
[15/03/2018 11:03:14 PM] at Tux.Workers.RollCall.Azure.AzureTable.Init(String tableName)
[15/03/2018 11:03:14 PM] at Tux.Workers.RollCall.Function1.<Run>d__0.MoveNext()
[15/03/2018 11:03:14 PM] Function completed (Success, Id=438dae86-18a8-4c85-b121-3918e2307ca4, Duration=122ms)
[15/03/2018 11:03:14 PM] Executed 'Function1' (Succeeded, Id=438dae86-18a8-4c85-b121-3918e2307ca4)
No matter how I do this error always occur whenever trying to calling Cloud Service in Azure function project. I can see the Microsoft.WindowsAzure.Storage.dll file in the bin directory inside the project. I also see the dll inside
C:\Users\klam0\.nuget\packages\windowsazure.storage\8.6.0
When I create a basic console application, I have no problem calling the Cloud to get the table reference.
Do I need to configure something on the portal if I just run the project locally?

Deploying Angular-Fullstack (MEAN) on Google App Engine

I've generated a project with Yeoman Angular-Fullstack generator (https://github.com/angular-fullstack/generator-angular-fullstack).
I created an app.yaml and tried to deploy the project on GAE with command:
gcloud app deploy
But I'm getting an error:
ERROR: (gcloud.app.deploy) Error Response: [13] Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).
Any tips on how to debug the gcloud deploy? I'm running the latest gcloud SDK.
--
Here's a longer debug trace:
Updating service [default]...-DEBUG: Operation [apps/<MY-PROJECT>/operations/63e50c89-da5f-4697-aeea-447865a82cc4] not complete. Waiting 5s.
Updating service [default]...|DEBUG: Operation [apps/<MY-PROJECT>/operations/63e50c89-da5f-4697-aeea-447865a82cc4] complete. Result: {
"metadata": {
"target": "apps/<MY-PROJECT>/services/default/versions/20160804t151734",
"method": "google.appengine.v1beta5.Versions.CreateVersion",
"user": "<MY-EMAIL>#gmail.com",
"insertTime": "2016-08-04T12:16:31.905Z",
"endTime": "2016-08-04T12:24:03.526Z",
"#type": "type.googleapis.com/google.appengine.v1beta5.OperationMetadataV1Beta5"
},
"done": true,
"name": "apps/<MY-PROJECT>/operations/63e50c89-da5f-4697-aeea-447865a82cc4",
"error": {
"message": "Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).",
"code": 13
}
}
Updating service [default]...failed.
DEBUG: (gcloud.app.deploy) Error Response: [13] Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).
Traceback (most recent call last):
File "/Users/jp/softaa/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 719, in Execute
result = args.calliope_command.Run(cli=self, args=args)
File "/Users/jp/softaa/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 1404, in Run
resources = command_instance.Run(args)
File "/Users/jp/softaa/google-cloud-sdk/lib/surface/app/deploy.py", line 57, in Run
return deploy_util.RunDeploy(self, args)
File "/Users/jp/softaa/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 215, in RunDeploy
api_client.DeployService(name, version, service, manifest, image)
File "/Users/jp/softaa/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/appengine_api_client.py", line 89, in DeployService
return operations.WaitForOperation(self.client.apps_operations, operation)
File "/Users/jp/softaa/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/api/operations.py", line 70, in WaitForOperation
encoding.MessageToPyValue(completed_operation.error)))
OperationError: Error Response: [13] Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).
ERROR: (gcloud.app.deploy) Error Response: [13] Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).
GAE does not come with Mongo. You have two options
Use GAE flex and build your own mongo container and use it
Use a Mongo cloud provider like https://mlab.com and they even have a free version to test.
If your question is just about finding the cause of this error, I would recommend using the Development Server on your localhost to find the error.
Without taking a deeper look, I guess the Node part does not fulfil the requirements for GAE or you are trying to deploy to a region where Node Applications are not supported.

Resources