What is the best way to use F# in Azure Functions at the moment? I want my function to have both input and output bindings (e.g. to queues or event hubs)
What I found so far:
Is there a way to take an F# function with inputs and output and host it as a Azure Function directly? Something similar to C# Run
method?
Ideally, inputs and outputs should be strongly typed: an object, record or discriminated union.
“F-strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is really an expression evaluated at run time, not a constant value. In Python source code, an f-string is a literal string, prefixed with f , which contains expressions inside braces.
To create an f-string, prefix the string with the letter “ f ”. The string itself can be formatted in much the same way that you would with str. format(). F-strings provide a concise and convenient way to embed python expressions inside string literals for formatting.
For example, "print %d" % (3.78) # This would output 3 num1 = 5 num2 = 10 "%d + %d is equal to %d" % (num1, num2, num1 + num2) # This would output # 5 + 10 is equal to 15. The %f formatter is used to input float values, or numbers with values after the decimal place.
The %s operator is put where the string is to be specified. The number of values you want to append to a string should be equivalent to the number specified in parentheses after the % operator at the end of the string value.
The templates are only meant to be starting points - you can add additional input/output bindings to them easily in the portal "Integrate" tab. For example, if you add a new Blob output named result
and bound to blob path "test-output/%rand-guid%"
, you can write script like the below that writes a blob:
open System
open System.IO
let inputPath = Environment.GetEnvironmentVariable("input")
let input = File.ReadAllText(inputPath)
let message = sprintf "F# script processed queue message '%s'" input
System.Console.Out.WriteLine(message)
let resultPath = Environment.GetEnvironmentVariable("result")
File.WriteAllText(resultPath, input);
Regarding more strongly typed "first class" support for F#, as I mentioned in the forum post you linked to, we're working on it :) For now, F# is in the bucket with all the other out of proc script types, where the communication mechanism in and out of the binding pipeline is via environment variables as you can see above.
Now F# is native!
Thanks to the excellent work by the F# team including Don Syme and Tomas Petricek, we're happy to announce we finally support F# in a first-class fashion in Azure Functions.
https://blogs.msdn.microsoft.com/appserviceteam/2016/09/01/azure-functions-0-5-release-august-portal-update/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With