Cloud Function getting 429 with example code

Hi,

We're using a data action to call a Cloud Function on GCP

This has started to return 429 errors

This is the error from GCP

{
  "error": {
    "code": 429,
    "message": "Quota exceeded for quota metric 'Test function' and limit 'Test function per minute' of service 'cloudfunctions.googleapis.com' for consumer 'project_number:XXXXXXXXXXXX'.",
    "status": "RESOURCE_EXHAUSTED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "RATE_LIMIT_EXCEEDED",
        "domain": "googleapis.com",
        "metadata": {
          "quota_metric": "cloudfunctions.googleapis.com/test_call_requests",
          "service": "cloudfunctions.googleapis.com",
          "consumer": "projects/XXXXXXXXXXXX",
          "quota_limit": "TestCallRequestsPerMinutePerProject"
        }
      }
    ]
  }
}

It looks like we are using the test URL rather than the trigger URL, after following the example in the Genesys docs. (See GCP docs about rate limits for calling the test URL).

If we switch to using the trigger URL we get a 401 error, or a 403 if we set the Cloud Function ingress to Internal Only. The Data Action is set up to use an integration which has GCP service account credentials

Are you able to advise how to configure the data action, integration, service account or Cloud Function so that we can call the Trigger URL, please

Also, please can you update the docs so the example doesn't use the Cloud Function's test URL

Many thanks

Hi James,

I am not quite sure what you are asking for here, but the error you are getting is a rate-limit error being returned by your Google Cloud provider endpoint. Usually, a 429 indicates you are calling the endpoint too many times within a minute and the service starts throwing a 429 indicating you should back off. A 403 would be an authorization issue so you need to setup your auth (usually some kind of auth token in the header) in the data action to pass the auth token to the endpoint.

Hope that helps.

Thanks,
John Carnell
Manager, Developer Engagement

Hi John,
As far as I can tell, you can call a Cloud Function with two URLs

The test URL is rate limited and is not meant for production use. The Genesys docs show the test URL being used. We have set up a custom integration with GCP service account credentials and our data action, using the test URL, works fine until we use it in production since we start breaching the test URL quota and getting 429 errors.

But if instead we use the trigger URL, we get a 401 error

So

  • I think the docs are wrong to suggest using the test URL since it is not suitable for production
  • I wondered if you were able to advise how to configure a Data Action to use a Cloud Function with GCP service account credentials since although the method suggested in the docs works with test URLs it doesn't seem to work with trigger URLs

Regards,
James

EDIT:
When intercepting the request using ngrok, I can see that there is a Bearer token in the Authorization header. The response from Google includes this in the headers:

Www-Authenticate: Bearer error="invalid_token" error_description="The access token could not be verified"

The response is:

<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL <code>/FUNCTION_NAME</code>.</h2>
<h2></h2>
</body></html>

Hi James,

I will pass on your request to update the document to the data actions team. I am also going to see if anyone on my team has worked with GCP before (most of them have worked only with AWS). I would suggest you take data actions out of the picture (for now) and just try to get the endpoint invoked via something like CURL or POSTMAN. Usually, with this type of thing, it's missing a parameter or the auth token has not been properly encoded (e.g. base64). POSTman is a heck of a lot easier to debug with than data actions because you can more easily manipulate the headers.

Let me talk with a few people and see if I can stir up anything.

Thanks,
John Carnell
Manager, Developer Engagement

Thanks John.

Please bear in mind that the authentication, using the GCP service account credentials, is done by the Genesys Cloud Function integration, so if there is a problem with the format of the auth token this isn't something that we can fix at our end

You seem to be encountering the issue we did when we tried to use triggers. We could only get permissions on a function to work with triggers if it ran without any permission schecks by being public.
We could not find any way to get a permission set on the FUNCTION that matched our authentication. Only the FUNCTION call endpoint seemed to work correctly for security.
This is why we recommend that triggers were unsuitable for production usage.

We are working on getting a contact at Google to work on this as we did not realize that the FUNCTION:call endpoint was being restricted by Google.

Following up, I looked into the permissions docs, and there are a couple things you could try.We will try them to and change the docs if they work.
The Function documentation, Authenticating for invocation  |  Cloud Functions Documentation  |  Google Cloud, describes a

  1. User permission, cloudfunctions.functions.invoke

  2. Service permission, roles/cloudfunctions.invoker.

Try setting those on the IAM role assigned to the service account and it's permissions to your function.

We found what we need. It is a different type of JWT auth than what they are using for Cloud API endpoints, or GSuite endpoints. Authenticating for invocation  |  Cloud Functions Documentation  |  Google Cloud

The JWT auth for this is not like the auth we use for GSuite, or GooglCloud endpoints. We will need to implement new code to make this work correctly.

1 Like

Hey James,

We have a fix for this ready to test. Please shoot me a private message with your OrgId and I will set you up to test it out.

--Jason

Hi Jason, Greg,

Great news - sorry I missed these replies. I'll be in touch

Thanks,
James

Hi @Jason_Mathison

Have DMed you with the results of our test

Thanks,
James

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.