question

gestion avatar image
gestion asked

Invocation of cloud script function failed

Hi there guys,

We've been testing the Azure Function API to try and get rid of execution time spikes on our CloudScript functions.

We first followed the guide from the docs to get used to Azure Functions by themselves. Everything was fine, worked like a charm both locally and remote by calling functions from a browser.

Then we switched to calling those Azure functions from PlayFab, using our game made in Unity. At first, we made the call without changing the AzureFunction function, just to check that AzureFunction calls could be made from PlayFab. We followed the guide from PlayFab docs to link the function and the call was made, with the following error showing:

/CloudScript/ExecuteFunction: The function TestAzureFunction was terminated after the maximum execution time limit: 10000ms

We thought that the error came from calling a non queue function, so we searched for any more in-depth docs, which we didn't find. So in order to get a proper call we just followed the docs, left the Azure docs example and copied the exact same code as the example in the PlayFab docs.

using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using PlayFab;
using PlayFab.Plugins.CloudScript;


namespace PlayFabCS2AFTests.HelloWorld
{
    public static class HelloWorld
    {
        [FunctionName("HelloWorld")]
        public static async Task<dynamic> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req,
            ILogger log)
        {
            /* Create the function execution's context through the request */
            var context = await FunctionContext<dynamic>.Create(req);
            var args = context.FunctionArgument;


            var message = $"Hello {context.CurrentPlayerId}!";
            log.LogInformation(message);


            dynamic inputValue = null;
            if (args != null && args["inputValue"] != null)
            {
                inputValue = args["inputValue"];
            }


            log.LogDebug($"HelloWorld: {new { input = inputValue} }");


            return new { messageValue = message };
        }
    }
}

So, to our surprise, we now get an invocation failure:

/CloudScript/ExecuteFunction: Invocation of cloud script function HelloWorldfailed

We configured everything according to the docs and we deployed the new version but when it comes to use the function in the docs, there's a function invocation error.

Has anyone encountered the same problem? Does anyone know where the error may be coming?

Thanks in advance, guys.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

andymaddison avatar image andymaddison commented ·

Is FunctionExecutionContext defined in Playfab.Plugins.Cloudscript?

I did the command dotnet add package PlayFabAllSDK to add the sdk in VS Code but I don't seem to have that Playfab.Plugins.Cloudscript available.

0 Likes 0 ·
gestion avatar image gestion andymaddison commented ·

I had to add the Playfab.Plugins.Cloudscript package by itself. It seemed like it was not included in PlayFabAllSDK package.

0 Likes 0 ·
gestion avatar image gestion gestion commented ·

@andymaddison same way as the PlayFabAllSDK package. This one is called PlayFabCloudScriptPlugin if I recall correctly. I think it was something like this:

dotnet add package PlayFabCloudScriptPlugin

I think the version I installed was 1.53-alpha.

1 Like 1 ·
Show more comments
franklinchen avatar image
franklinchen answered

Hi @gestion, @Sami Atiq,

Recently, the guidance of Cloudscript using Azure functions is changing, please take a look at the sample code: https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart#playfab-cloudscript-context-variables-and-server-sdks-

And please check out the helper class explained here, you can find the FunctionExecutionContext and other useful classes.

15 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gestion avatar image gestion commented ·

Hi @FranklinChen,

Thanks for the answer. We will look into that new sample code and try that out.

0 Likes 0 ·
gestion avatar image gestion gestion commented ·

Quick update: Updated the tools, downloaded helper class, copied the example code, uploaded the updated function and...

/CloudScript/ExecuteFunction: Invocation of cloud script function HolaMundo failed

Tried from a player inside PlayFab (no Unity app or anything) and got a bad request:

"Error": {
        "Code": 400,
        "Status": "BadRequest",
        "ErrorCode": 1473,
        "ErrorMessage": "Invocation of cloud script function HolaMundo failed"
    }

The request was made by PlayFab, not even from our code, so we are completely lost here.

0 Likes 0 ·
franklinchen avatar image franklinchen gestion commented ·

Hi @gestion, Interesting, I just tried your code, it worked well. Based on your Log stream, it should be a V3 function.
Firstly, let's ensure that you have registered your function correctly in PlayFab. One thing I noticed is the message "C# HTTP trigger function processed a request." is showing in your log but the corresponding code in function is missing, are you sure this log is leading to the right func app you registered in PlayFab? If not, please check the function url to see if it's correct.

Secondly, how you called the ExecuteFunction API? Which tool(like postman)? What's the request body. For example, this is the request I requested to make it work:

{
  "FunctionName": "HelloWorld",
  "FunctionParameter": {
    "inputValue": "Franklin"
  },
  "GeneratePlayStreamEvent": true,
  "Entity": {
    "Id": "{
                     {PlayerEntityId}}",
    "Type": "title_player_account",
    "TypeString": "title_player_account"
  }
}
1 Like 1 ·
Show more comments
Citrus Yan avatar image
Citrus Yan answered

Hi @gestion

Invocation failure is a known issue in your case, I will report this to the related team to investigate, any updates will keep you informed. Thanks for your feedback:)

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

gestion avatar image gestion commented ·

Thanks @Citrus Yan for the answer. Just so we can continue our learning of the AzureFunctions feature, is there a more in-depth docs for calling AzureFunctions queue functions?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan gestion commented ·

Sorry, there is no in-depth doc for calling queue functions on PlayFab's doc portal yet. Please visit the Azure Functions documentation for more information.

0 Likes 0 ·
Sami Atiq avatar image Sami Atiq commented ·

Hi @Citrus Yan I am facing the same issue. I followed the same guide and got the same error as mentioned by @gestion. Any updates on that?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.