This article explains how return values work inside a function.
If there are multiple output bindings, use the return value for only one of them.
Here's C# code that uses the return value for an output binding, followed by an async example:
[FunctionName("QueueTrigger")]
[return: Blob("output-container/{id}")]
public static string Run([QueueTrigger("inputqueue")]WorkItem input, ILogger log)
{
string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
log.LogInformation($"C# script processed queue message. Item={json}");
return json;
}
[FunctionName("QueueTrigger")]
[return: Blob("output-container/{id}")]
public static Task<string> Run([QueueTrigger("inputqueue")]WorkItem input, ILogger log)
{
string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
log.LogInformation($"C# script processed queue message. Item={json}");
return Task.FromResult(json);
}
Here's the output binding in the function.json file:
{
"name": "$return",
"type": "blob",
"direction": "out",
"path": "output-container/{id}"
}
Here's the C# script code, followed by an async example:
public static string Run(WorkItem input, ILogger log)
{
string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
log.LogInformation($"C# script processed queue message. Item={json}");
return json;
}
public static Task<string> Run(WorkItem input, ILogger log)
{
string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
log.LogInformation($"C# script processed queue message. Item={json}");
return Task.FromResult(json);
}
Here's the output binding in the function.json file:
{
"name": "$return",
"type": "blob",
"direction": "out",
"path": "output-container/{id}"
}
Here's the F# code:
let Run(input: WorkItem, log: ILogger) =
let json = String.Format("{{ \"id\": \"{0}\" }}", input.Id)
log.LogInformation(sprintf "F# script processed queue message '%s'" json)
json
Here's the output binding in the function.json file:
{
"name": "$return",
"type": "blob",
"direction": "out",
"path": "output-container/{id}"
}
Here's the JavaScript code:
module.exports = function (context, input) {
var json = JSON.stringify(input);
context.log('Node.js script processed queue message', json);
return json;
}
Here's the output binding in the function.json file:
{
"name": "Response",
"type": "blob",
"direction": "out",
"path": "output-container/{blobname}"
}
Here's the PowerShell code that uses the return value for an http output binding:
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $blobname
})
Here's the output binding in the function.json file:
{
"name": "$return",
"type": "blob",
"direction": "out",
"path": "output-container/{id}"
}
Here's the Python code:
def main(input: azure.functions.InputStream) -> str:
return json.dumps({
'name': input.name,
'length': input.length,
'content': input.read().decode('utf-8')
})
Here's Java code that uses the return value for an output binding:
@FunctionName("QueueTrigger")
@StorageAccount("AzureWebJobsStorage")
@BlobOutput(name = "output", path = "output-container/{id}")
public static String run(
@QueueTrigger(name = "input", queueName = "inputqueue") WorkItem input,
final ExecutionContext context
) {
String json = String.format("{ \"id\": \"%s\" }", input.id);
context.getLogger().info("Java processed queue message. Item=" + json);
return json;
}