Issue
I created a function (2nd gen) in the Google Cloud Functions service. The function is written in Python (v. 3.11) and the deployment is done as a ZIP upload. The function responds correctly if call it with Postman, providing the Google Identity Token in the Authentication header. But when I call it programmatically in Java, I always get the following error:
NOT_FOUND: Function <cloud_function_name> in region europe-west6 in project <project> does not exist
It clearly does exist so: what does this error mean?
In Java I use the google-cloud-functions library:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-functions</artifactId>
<version>2.32.0</version>
</dependency>
and I provide the program with the authentication by executing:
gcloud auth application-default login
The code:
private static final String CLOUD_FUNCTION_NAME = "the_name";
public GCPFunctionsClient(String project, String location) {
this.project = project;
this.location = location;
try {
client = CloudFunctionsServiceClient.create();
} catch (IOException e) {
throw new RuntimeException(e);
}
this.mapper = new ObjectMapper();
}
// ...
public String callFunction(String operation, String obuIdentifier){
GenericFunctionRequest request = GenericFunctionRequest.builder().build();
try {
CallFunctionResponse response = client.callFunction(nameOf(CLOUD_FUNCTION_NAME), serialize(request));
var responseContent = response.getResult();
if(log.isInfoEnabled()){
log.info("Cloud functions response: {}" + responseContent);
}
return responseContent;
}catch (Exception e){
throw new CloudFunctionCallException(e);
}
}
private String nameOf(String functionName) {
return CloudFunctionName.of(project, location, functionName).toString();
}
the name of the function is correct, I double checked it.
Solution
I believe this is because you're using the Cloud Functions v1 API to call a Cloud Functions gen2 function. If you use Cloud Functions gen1, your code should work. I've reproduced this using the C# client library rather than the Java one, but I'm sure it's the same cause.
The Cloud Functions v2 API doesn't currently have an equivalent of the CallFunction RPC... so for the moment, I'd recommend simply making an HTTP request directly with an HTTP client, or use gen1 functions for now.
Answered By - Jon Skeet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.