question

Kim Strasser avatar image
Kim Strasser asked

Azure Functions: "Invocation of cloud script function NewFunction failed"

I always get this error message in the client code: "Invocation of cloud script function NewFunction failed".

I get no event in PlayStream when the error happens. What does this error message mean and what is wrong with my code?

How can I find out if my Azure function works correctly? I don't know if there is a problem with my Azure function or with the client code that calls the Azure function.

Client code:

var result = await PlayFabCloudScriptAPI.ExecuteFunctionAsync(new ExecuteFunctionRequest()
{
    Entity = new PlayFab.CloudScriptModels.EntityKey()
    {
        Id = entityid,
        Type = entitytype,
    },
    FunctionName = "NewFunction",
    FunctionParameter = new { NewDisplayname = "Sydney" },
    GeneratePlayStreamEvent = true
});


if (result.Error != null)
{
         
}
else
{
    if (result.Result.FunctionResultTooLarge ?? false)
    {
        Console.WriteLine("This can happen if you exceed the limit that can be returned from an Azure Function, See PlayFab Limits Page for details.");
    }


    Console.WriteLine("The " + result.Result.FunctionName + "function took " + result.Result.ExecutionTimeMilliseconds.ToString() + " to complete.");
    Console.WriteLine(result.Result.FunctionResult.ToString());
}

Azure Function:

namespace My.Functions
{
    public static class NewFunction
    {
        [FunctionName("NewFunction")]
        public static async Task<dynamic> MakeApiCall(
            [HttpTrigger(AuthorizationLevel.Anonymous, "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 desireddisplayname = args["NewDisplayname"];
 
            /* Create the request object through the SDK models */
            var request = new UpdateUserTitleDisplayNameRequest();
            request.PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId;
            request.DisplayName = desireddisplayname;
            /* Use the ApiSettings and AuthenticationContext provided to the function as context for making API calls. */
            var adminApi = new PlayFabAdminInstanceAPI(context.ApiSettings, context.AuthenticationContext);
         
            /* The PlayFabServerAPI SDK methods provide means of making HTTP request to the PlayFab Main Server without any 
             * extra code needed to issue the HTTP requests. */
            return await adminApi.UpdateUserTitleDisplayNameAsync(request);
        }
    }
}

I have chosen "Authorization level: Anonymous" when I created my Azure project in Visual Studio Code. And I have added "PLAYFAB_DEV_SECRET_KEY": "...", and "PLAYFAB_TITLE_ID": "..." to my local.settings.json file.

In addition, I selected the Register Function button in my PlayFab account and I have created the following cloud script function:

Trigger type: HTTP

Function name: NewFunction

Function URL: https://myplayfabfunctionapp.azurewebsites.net/api/NewFunction
CloudScript
10 |1200

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

1 Answer

·
Seth Du avatar image
Seth Du answered

By default, the local.setting.json won't be uploaded. You will need to click "Upload Settings" after the codes have been uploaded successfully, please refer to: https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=csharp#publish-application-settings

Otherwise, you may manually configure the settings on Azure Portal on [Configuration] => [Application Settings] => [New Application settings]. Input “PLAYFAB_DEV_SECRET_KEY” as the key and your secret key as value. Of course, you may modify the source code to any key you want. It will work as long as the code matches the Azure Portal configuration.

PS. To troubleshot Azure Function, you may start streaming log, and after that, call PlayFab API to see the log output in the console.


2 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.

Kim Strasser avatar image Kim Strasser commented ·

"Start Streaming Logs" is not displayed in my Visual Studio Code menu. Why is it not displayed when I click on my function?

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Kim Strasser commented ·

It will need to publish to the online azure portal:

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.