nodejs-docs-samples
nodejs-docs-samples copied to clipboard
Google Cloud Retail: updateMask values must be snake_case despite being camelCase on the Product Interface
See: https://github.com/googleapis/google-cloud-node/issues/4195
I think this is still an issue. However it executes okay with the API but the SDK throws an error.
async function updateMinInstances(
functionName: string,
functionRegion: string,
minInstances: number
): Promise<void> {
const name = `projects/${PROJECT_ID}/locations/${functionRegion}/functions/${functionName}`;
try {
const request: protos.google.cloud.functions.v1.IUpdateFunctionRequest = {
function: {
name,
minInstances,
maxInstances: null // Setting maxInstances to null (or omitting it) effectively removes the limit.
},
// Corrected the updateMask to be an object with a 'paths' array.
updateMask: {
paths: ['min_instances', 'max_instances']
}
};
// Make the API call to update the function
const [operation] = await client.updateFunction(request);
const [response] = await operation.promise();
console.log(
`Successfully updated minInstances to ${minInstances} for function: ${functionName}`,
response
);
} catch (error) {
// We cast the error to be able to access its message property.
console.error(`Error updating function ${functionName}: ${(error as Error).message}`, error);
}
}