Using azure function output parameters with Dropbox connector - azure

My flow is very simple: I want to have an azure function that runs once a day and they use its output to create a file in Dropbox.
The function does some processing and returns an object with 2 properties, a FileName and a FileContent, both are strings.:
return new AzureFunctionResponse
{
FileName = $"TestFile-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}",
FileContent = "This is the file content"
};
My problem is that I don't know how to use those 2 properties to setup my Dropbox connector
Here's my LogicApp flow:
I'd like to use the FileName and FileContent returned from my AzureFunction to populate the respective field in the Dropbox connector but I have no idea how to set this up. I've looked for documentation, but maybe I'm not looking at the right place because I'm not finding anything.
Also here are the bindings in my function.json file, if that can be of any help.
{
"disabled": false,
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"webHookType": "genericJson",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
}

Using the Parse JSON action after the function should do exactly what you need. Will parse output and make them available for you in the next step.

As alternative, you can implement the whole thing without using Logic Apps.
Make an Azure Function with Timer input trigger and Api Hub File output binding. No HTTP bindings are needed.
See this question for an example.

Related

Pass Parameter to Azure Powershell Function

I'm new to the Azure environment. I want to execute an .exe file by passing blob storage as an input and output parameter
below is my Json Function and PowerShell code I am not sure how to pass the input blob storage file as parameter and get the output on the blob storage.
I tried to run the below code but i am getting error
Function.json
{
"bindings": [
{
"name": "Timer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
},
{
"name": "inputBlob",
"direction": "in",
"type": "blob",
"path": "inputfilepath/{name}",
"connection": "test23_STORAGE"
},
{
"name": "outputBlob",
"direction": "out",
"type": "blob",
"path": "outputfilepath/{name}",
"connection": " test23_STORAGE"
}
]
}
Run.ps1
# Input bindings are passed in via param block.
param($Timer,$inputBlob,$outputBlob)
# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()
# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled.
if ($Timer.IsPastDue) {
Write-Host "PowerShell timer is running late!"
}
# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"
Set-Location "C:\home\site\wwwroot\TimerTrigger1"
.\Extractor.exe -F $inputBlob -E $outputBlob
Error
2022-09-10T07:09:45Z [Information] Executing 'Functions.TimerTrigger1' (Reason='This function was programmatically called via the host APIs.', Id=07f70ccc-3e39-4e98-a830-73bfda54d101)
2022-09-10T07:09:45Z [Error] Executed 'Functions.TimerTrigger1' (Failed, Id=07f70ccc-3e39-4e98-a830-73bfda54d101, Duration=7ms)
AFAIK, we cannot use multiple input triggers, but we can use multiple input/output binding of the same trigger in one trigger function.
I want to execute an .exe file by passing blob storage as an input and output parameter
This might be done in 2 ways either fetching that .exe file from the Storage blob container path and running it or using the WebJobs with CRON Tab expression for these kinds of tasks.
From the Azure Functions, define one function for triggering the .exe file at runtime to run and another function for storing the output of that .exe application in the blob storage.

How to set the output bindings for name and location in an Azure function using python?

I can't quite seem to get the output bindings to enable a file to be saved to blob storage. I have created an Azure Function using Python, that uses a CosmosDB Change Feed trigger. I need to save that document to blob storage.
I've set-up the function.json file as follows:
{
"scriptFile": "__init__.py",
"bindings": [
{
"type": "cosmosDBTrigger",
"name": "documents",
"direction": "in",
"leaseCollectionName": "leases",
"connectionStringSetting": "cosmos_dev",
"databaseName": "MyDatabase",
"collectionName": "MyCollection",
"createLeaseCollectionIfNotExists": "true"
},
{
"type": "blob",
"direction": "out",
"name": "outputBlob",
"path": "raw/changefeedOutput/{blobname}",
"connection": "blobStorageConnection"
}
]
}
So the trigger will get a documents like the following:
{ "id": "documentId-12345",
other sections here
"entity": "customer"
}
In the init.py file I have the base code of
def main(documents: func.DocumentList) -> func.Document:
logging.info(f"CosmosDB trigger executed!")
for doc in documents:
blobName = doc['id'] + '.json'
blobFolder= doc['entity']
blobData = doc.to_json()
I think i need to add in the def something like 'outputBlob: func.Out' but unsure how to proceed
Looking at the examples on github
https://github.com/yokawasa/azure-functions-python-samples/tree/master/v2functions/blob-trigger-watermark-blob-out-binding
it look like i have to
outputBlob.set(something)
So i'm looking for how to set up the def part and send the blob to the location that i've set from the data in the cosmosdb document.
I have tried the following:
def main(documents: func.DocumentList, outputBlob: func.Out[str] ) -> func.Document:
logging.info(f"CosmosDB trigger executed!")
for doc in documents:
blobName = doc['id'] + '.json'
outputBlob.set(blobName)
and get the result:
CosmosDB trigger executed!
Executed 'Functions.CosmosTrigger_py' (Failed, Id=XXXXX)
System.Private.CoreLib: Exception while executing function: Functions.CosmosTrigger_py. Microsoft.Azure.WebJobs.Host: No value for named parameter 'blobname'.
I could just call the connection stuff from the os.enviro, and get the connection string that way, I think and use the standard create_blob_from_text, with location, name and blob data,
block_blob_service.create_blob_from_text(blobLocation, blobName, formattedBlob)
Any pointers would be great

How to dynamically set blob name to store in Blob storage in azure function nodejs?

I have a activity function that should store message in Blob storage.I can overwrite a file in blob storage but i need to store data in different name.how to do that? Azure function doesn't support dynamic binding in nodejs.
Find one workaround, see whether it's useful.
Along with blob output binding, there's an activity trigger to receive message msg, we can put self-defined blob name in msg for blob binding path to consume.
In your orchestrator function which calls Activity function
yield context.df.callActivity("YourActivity", {'body':'messagecontent','blobName':'myblob'});
Then Activity function code should be modified
context.bindings.myOutputBlob = context.bindings.msg.body;
And its function.json can use blobName as expected
{
"bindings": [
{
"name": "msg",
"type": "activityTrigger",
"direction": "in"
},
{
"name":"myOutputBlob",
"direction": "out",
"type": "blob",
"connection": "AzureWebJobsStorage",
"path": "azureblob/{blobName}"
}
],
"disabled": false
}

Azure Logic App: How to save HTTP Connector's body content to OneDrive file?

I have a simple Azure Logic App with the following components:
Recurrence
HTTP Get from HTTPS url
I've tried to configure the next component to save the HTTP response body to OneDrive with OneDrive Connector configured as follows:
FilePath: ApiTest/test.json
Content: #{body('http')}
Content Transfer Encoding: None
This gives the following error:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'microsoftonedriveconnector' inputs at line '1' and column '11': 'Template language expression cannot be evaluated: one of string interpolation segment value has unsupported type 'Object'. Please convert the value to string using the 'string()' function.'."}
If I then use #{string(body('http'))} I get:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'microsoftonedriveconnector' inputs at line '1' and column '11': 'The template language function 'string' was invoked with an invalid parameter. The value cannot be converted to the target type.'."}
How can I use the body of HTTP Connector and save it to One Drive?
I don't have an answer, but I am wrestling with this very issue right now. I will post if I find a solution and would be very interested in case any one else finds a solution. I do find one thing interesting. There is a header and body option on the consuming end of my Http Connector which works when it runs. The error (as the above poster notes) occurs when passing that value to the next card. But, when I look at the output (link) on the run tab, I see a json value for the header and for the body. Does this need to be wrapped in a json parser?
This works for me just fine and generated the file in the /random/test.txt folder, however I believe the problem in your case is that you are downloading a JSON file which is causing it to be interpreted as an object by the engine.
I'll follow up with the team and maybe we need a "ToJson" call, or a way to "Passthrough", or make "String" more "flexible" (though that could be weird).
"fileContent": {
"Content": "#{body('http')}",
"ContentTransferEncoding": "None"
},
Actions in code view looks like:
"http": {
"type": "Http",
"inputs": {
"method": "GET",
"uri": "http://www.carlosag.net/"
},
"conditions": []
},
"microsoftonedriveconnector": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/xxx/resourceGroups/zzz/providers/Microsoft.AppService/apiApps/MicrosoftOneDriveConnector",
"gateway": "https://yyy.azurewebsites.net"
},
"operation": "UploadFile",
"parameters": {
"filePath": "random/test.json",
"fileContent": {
"Content": "#{body('http')}",
"ContentTransferEncoding": "None"
},
"overwrite": true
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/...')"
}
},
You should try "#body('http')". I believe this will work. "#{body('http')}" is a form of string interpolation: expected output value is string and not a JSON.
I initialized a String variable 'Content' and set the value to the body of the HTTP.
#{body('HTTP')}
And then I convert the String to JSON to read the desired node with an expression.
json(variables('Content'))?['ExcelFile']
I went a step further and base64 decoded to binary in order to upload to Sharepoint. Going to OneDrive would likely be the same.
base64ToBinary(json(variables('Content'))?['ExcelFile'])

What format will a binary file output from the Storage Blob Connector be in when passed to the following action?

In an Azure App-Service Logic App I have an AzureStorageBlobConnector which retrieves a file from storage. The file is being retrieved as binary and without setting any ContentTransferEncoding. My connector definition (subscription details replaced with 'x') looks like this:
"azurestorageblobconnector": {
"type": "ApiApp",
"inputs": {
"apiVersion": "2015-01-14",
"host": {
"id": "/subscriptions/x/providers/Microsoft.AppService/apiapps/azurestorageblobconnector",
"gateway": "https://x.azurewebsites.net"
},
"operation": "GetBlob",
"parameters": {
"BlobPath": "#triggers().outputs.body.Properties['FilePath']",
"FileType": "Binary"
},
"authentication": {
"type": "Raw",
"scheme": "Zumo",
"parameter": "#parameters('/subscriptions/x/resourcegroups/x/providers/Microsoft.AppService/apiapps/azurestorageblobconnector/token')"
}
},
"repeat": null,
"conditions": []
},
I want to author a custom Api Connector to receive this file, make some changes to it, then return it for the next step in the workflow.
What form will the file be in when the storage blob connector passes it to the next connector as #body('azurestorageblobconnector').Content? Will it be HttpPostedFile or a Stream or Multipart content in the body, or something else?
It depends on how you configure the Connector, if you choose "Binary" then it will come as a string in Base64 encoded.
If you choose Text, then it will be "the raw text".
One way to deal with that, is in your API App try to Convert.FromBase64String and if that succeeds then you got yourself a byte array with the actual bytes. If it does not succeed then you can assume that is the raw text content of the file.

Resources