azure-functions-host: [CustomHandler]Payload Access in Pure HTTP Azure Function Not Working with Custom Handler

I’m using the Ballerina language’s custom Azure Functions handler in implementing a pure HTTP function. The code is as follows.

import ballerina/http;
import ballerinax/azure.functions as af;

@af:Function
public function hello(@af:HTTPTrigger { authLevel: "anonymous" } http:Request req) 
                      returns @af:HTTPOutput string|error {
    return "Hello, " + check <@untainted> req.getTextPayload() + "!";
}

I built, deployed, and invoked the function in the following manner:

$ ballerina build functions.bal 
Compiling source
	functions.bal

Generating executables
	functions.jar
	@azure.functions:Function: hello

	Run the following command to deploy Ballerina Azure Functions:
	az functionapp deployment source config-zip -g <resource_group> -n <function_app_name> --src azure-functions.zip

$ 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": false,
  "author": "N/A",
  "author_email": "N/A",
  "complete": true,
  "deployer": "ZipDeploy",
  "end_time": "2020-08-05T03:14:09.1031973Z",
  "id": "83b96c42881b4c61884e3c3731768589",
  "is_readonly": true,
  "is_temp": false,
  "last_success_end_time": "2020-08-05T03:14:09.1031973Z",
  "log_url": "https://functions1777.scm.azurewebsites.net/api/deployments/latest/log",
  "message": "Created via a push deployment",
  "progress": "",
  "provisioningState": null,
  "received_time": "2020-08-05T03:13:58.5080037Z",
  "site_name": "functions1777",
  "start_time": "2020-08-05T03:13:58.9611253Z",
  "status": 4,
  "status_text": "",
  "url": "https://functions1777.scm.azurewebsites.net/api/deployments/latest"
}

$ curl https://functions1777.azurewebsites.net/api/hello -v
...
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=*.azurewebsites.net
*  start date: Sep 24 02:18:56 2019 GMT
*  expire date: Sep 24 02:18:56 2021 GMT
*  subjectAltName: host "functions1777.azurewebsites.net" matched cert's "*.azurewebsites.net"
*  issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT TLS CA 5
*  SSL certificate verify ok.
> GET /api/hello HTTP/1.1
> Host: functions1777.azurewebsites.net
> User-Agent: curl/7.64.0
> Accept: */*
> 
< HTTP/1.1 500 Internal Server Error
< Set-Cookie: ARRAffinity=bffb580df78d7165f60f8296e74f37e8d5a5ef15cfd49e51bf0d3e3f75c7c66d;Path=/;HttpOnly;Domain=functions1777.azurewebsites.net
< Request-Context: appId=cid-v1:ff099526-44ae-460a-86ca-2d534f6a7258
< Set-Cookie: ARRAffinity=06488d46fdc858266f881d039fdd1144de6081e33ee2d5ada365f466d37d6220;Path=/;HttpOnly;Domain=functions1777.azurewebsites.net
< Date: Wed, 05 Aug 2020 03:19:01 GMT
< Content-Length: 0
< 
* Connection #0 to host functions1777.azurewebsites.net left intact

The logs in Azure Functions App show the following:

2020-08-05T03:24:00.722 [Information] Executing 'Functions.hello' (Reason='This function was programmatically called via the host APIs.', Id=c9287ccd-3d0f-4285-b4ba-3ae4f7ec1287)
2020-08-05T03:24:00.836 [Error] Executed 'Functions.hello' (Failed, Id=c9287ccd-3d0f-4285-b4ba-3ae4f7ec1287, Duration=88ms)
No MediaTypeFormatter is available to read an object of type 'HttpScriptInvocationResult' from content with media type 'text/plain'.

I tried invoking the function with different content types as the input, but I still get the same log. This functionality used to work a little while back (I tested this scenario lastly on July 23’rd 2020), and it’s just starting to fail now. Did something change recently in relation to pure HTTP functions? any assistance on this matter is appreciated.

Investigative information

Timestamp: functions1777 Function App version: 2.0 Function App name: functions1777 Function name(s): hello Invocation ID: c9287ccd-3d0f-4285-b4ba-3ae4f7ec1287 Region: East US

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

No problem. Thanks for all the work on bringing Ballerina to Azure Functions. Please share any feedback you have and let us know if you run into any issues with the new changes. We hope to publish the docs for the new customHandler section soon (when the next version of Core Tools is released).