Azure / Azure/azure-functions-host
Azure Functions with a Custom Handler - Random Value Generation Not Consistent
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
I'm using the [Ballerina](https://ballerina.io/) language's custom Azure Functions handler in implementing a function. In it, I wanted to create a unique name for a blob. For that, I tried reading "sys.RandGuid" metadata as a unique value, and the expectation was, inside the function body, I can read in the same metadata value to used in extracting this same value. I need this same value for purposes later to look up the blob value. The code is similar to the following:
```ballerina
import ballerinax/azure.functions as af;
@af:Function
function doit(af:Context ctx,
@af:HTTPTrigger { authLevel: "anonymous" } string input,
@af:BlobOutput { path: "images/{sys.RandGuid}" } af:StringOutputBinding blob)
returns @af:HTTPOutput json {
blob.value = input;
return ctx.metadata.sys.RandGuid.toString();
}
```
A sample run of the above application is below:
```bash
$ ballerina build test.bal
Compiling source
test.bal
Generating executables
test.jar
@azure.functions:Function: doit
Run the following command to deploy Ballerina Azure Functions:
az functionapp deployment source config-zip -g -n --src azure-functions.zip
laf@laf-ThinkPad-X1-Carbon:~$ az functionapp deployment source config-zip -g functions1777 -n functions1777 --src azure-functions.zip
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
{
"active": true,
"author": "N/A",
"author_email": "N/A",
"complete": true,
"deployer": "ZipDeploy",
"end_time": "2020-08-04T23:14:19.736517Z",
"id": "aa57126d4ef74fe2982f638a1bf2df13",
"is_readonly": true,
"is_temp": false,
"last_success_end_time": "2020-08-04T23:14:19.736517Z",
"log_url": "https://functions1777.scm.azurewebsites.net/api/deployments/latest/log",
"message": "Created via a push deployment",
"progress": "",
"provisioningState": null,
"received_time": "2020-08-04T23:14:07.8137704Z",
"site_name": "functions1777",
"start_time": "2020-08-04T23:14:08.4075021Z",
"status": 4,
"status_text": "",
"url": "https://functions1777.scm.azurewebsites.net/api/deployments/latest"
}
$ curl -H "Content-Type: application/octet-stream" --data-binary "@input.jpeg" https://functions1777.azurewebsites.net/api/doit
79b6411a-4f44-44e8-96fa-c762ab8ec5e9
```
As we can see, in the last command of the function invocation, it returns the value "79b6411a-4f44-44e8-96fa-c762ab8ec5e9". But when I go check my blob in the "images" path, it had created a separate entry with the name "2b3ebcf5-d1b6-4d7a-816f-8ce8fb987859". So the point is, somehow in both places the values are different. I'm not sure how it can be since from the blob entry in the output binding, and also from the code, I read the same "sys.RandGuid" value. Is there any explanation for this?
My basic requirement is to getting a unique value for the blob value, and to read it from the code. It seems, from a custom handler, there is no approach for providing this name for the blob record as well. If there's any approach to do this, that would be actually better. Appreciate any help for this scenario.
Request Info:-
===========
- Timestamp: functions1777
- Function App version: 2.0
- Function App name: functions1777
- Function name(s) (as appropriate): doit
- Invocation ID: bf924e93-6b6d-4c8b-a7ae-28b33a9d88f7
- Region: East US
Contributor guide
Assessment
This issue has not been assessed yet.