Good day,
I am trying to execute a cloud run job with JobsClient in node.js. Below is my code:
export const trigger_cloud_run_job = () => {
let router = express.Router();
router.post(
"/file_upload/trigger_cloud_run_job",
validationMdw,
check_auth(),
async (req: ExtRequest, res) => {
console.log("run trigger")
let { modelPath, atlasPath } = req.body;
console.log("request body: ", modelPath, atlasPath )
try {
const project = `${process.env.GCP_PROJECT_ID}`;
const location = "europe-west3"
const jobId = 'benchmark-atlas';
const parent = `projects/${project}/locations/${location}`;
const {JobsClient} = require('@google-cloud/run').v2;
const runClient = new JobsClient();
// the job struct
const job = {
template: {
// parallelism: 0,
template: {
containers: [{
image: process.env.IMAGE_URL,
resources: {
limits: {
cpu: "1000m",
memory: "512Mi"
},
cpuIdle: false,
startupCpuBoost: false
},
env: [
{
name: "modelPath",
values: modelPath
},
{
name: "atlasPath",
values: atlasPath
}
],
}],
timeout: {
seconds: "1800",
nanos: 0
},
maxRetries: 3,
serviceAccount: process.env.JOB_SERVICE_ACCOUNT,
retries: "maxRetries"
}
}
};
const request = {
parent,
job,
jobId,
};
// Run request
try {
const [operation] = await runClient.createJob(request);
const [response] = await operation.promise();
console.log(response);
} catch (error) {
if (error.code === 6) {
console.log('Job already exists. Skipping creation.');
} else {
throw error;
}
}
} catch (error) {
console.error('Error creating or running Cloud Run Job:', error);
res.status(500).send({error: error.message});
}
});
return router;
};
When running this I get the following error:
Error creating or running Cloud Run Job: Error: 7 PERMISSION_DENIED: Permission ‘run.jobs.create’ denied on resource ‘projects/{projectID}/locations/europe-west3/jobs/benchmark-atlas’ (or resource may not exist).
The serviceAccount specified for the job creation is the compute@developer.gserviceaccount.com (default service account). Thus, it has all the required permissions to create an run a cloud run job. I have also successfully created a job locally with this service account.
gcloud run jobs create benchmark-atlas \
--image=gcr.io/{projectID}/{image}:latest \
--region=europe-west3 \
--project={projectID} \
--service-account={projectID}-compute@developer.gserviceaccount.com
Is there something that I may be missing? I am fairly new to GCP and therefore would appreciate any guidance you have. Thanks in advance!