Home > Net >  Azure powershell function with no input has failed execution because the input is not base-64
Azure powershell function with no input has failed execution because the input is not base-64

Time:09-21

I have a process that adds an entry to an Azure Storage Queue. It works like a champ. I run the code and I can see there is an entry in the queue, with the text I expect.

I have a web service that dequeues from the queue and processes the entry. I have published the web service to an Azure App Service. The web service responds to a GET. It works like a champ. I enter the URL to the method of the web service. I can see that the entries in the queue are not there after the web service finished, and I see that the they have been processed as I expect by looking at the results on the back end.

I want to tie these together. When an entry is enqueued, I want the web service to start. I want to use the Azure Function App. I have created the function app and added a function to it using the portal. The function trigger I want is that on an entry being added to the storage queue. I added a powershell function to the app, Powershell 7, using the template for queued items. I filled the AzureWebJobsSorage app setting with the connection string to the storage account. I get to the Code/Test. I replace the content of the function with:

& Invoke-WebRequest -Uri https://[service].azurewebsites.net/path/to/the/web/method

This line does what I expect when enter it in a PWSH terminal on my desk. What I expect is that I have an Azure function that expects no parameters and that will make a web request when an entry lands in the queue. The (C#-oid) function signature I want is

void f() {...}

When I Run this with the Test/Run button, I get an error that there is no parameter defined for the QueueIte.Stack. Right. The sample data from the framework isn't relevant, so I might expect that handing it a parameter it doesn't need might seem exceptional. I don't see in the portal how it is I can stop handing it a parameter it doesn't want.

I try it for real, by running the process that enqueues an item. I get a report of an error in the Monitor that "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."

It would seem that the function framework is somehow looking for input, and is disappointed with the input it gets, and doesn't know what to do with the input if it gets it. Please help me understand how I can make this function quit looking for input. What am I missing?

CodePudding user response:

What I expect is that I have an Azure function that expects no parameters and that will make a web request when an entry lands in the queue.

If I understand correctly, you want an Azure Function to trigger whenever a message is added to the queue but you don't want to do anything with that message (no parameters to the function).

If that's the case then unfortunately this won't work. Basically the intent behind a Queue Triggered Function is that you would want to work with that message. For a Queue Triggered Function (or for that matter any Azure Function), you will have to play by Azure rules in the sense that your method signature must match with what Azure Function runtime is expecting.

Inside your Function code, its up to you what you want to do with that message. You can even have an empty Function body (i.e. no code).

Furthermore, Queue Triggered Function expects the message body to be base64 encoded string. You will need to make changes to your process which writes messages in the queue so that you are sending base64 encoded data as message contents.


Coming to your specific case, I don't think your approach would work. Basically you would want Azure Function to trigger when a message is added to the queue however you would want to process that message in your web application. This will not work for 2 reasons:

  1. If the Function execution is successful, then as soon as the Function terminates, the message will be automatically deleted from the Queue by Function runtime.
  2. Function fetches the message in Peek-Lock mode by dequeuing the message. As long as the message is dequeued, it is not available to other consumers (your web application, for example). So if your web application tries to read the message, it won't find it.

What you could do instead is read the message contents in your Function code and post the message content to your web application and it can then work with that.

  • Related