I'm developing a Node.js application and trying to create a queue using Google Cloud Tasks, but I encounter the following error:
Error: 7 PERMISSION_DENIED: The principal (user or service account) lacks IAM permission "cloudtasks.queues.create" for the resource "projects/XXXXXX/locations/europe-central2" (or the resource may not exist).
Steps Taken:
1- Service Account Creation: I created a service account and assigned it the "Cloud Tasks Queue Admin" role (roles/cloudtasks.queueAdmin), which includes the cloudtasks.queues.create permission.
2- Client Configuration: I configured the Cloud Tasks client in my code as follows:
const { CloudTasksClient } = require('@google-cloud/tasks');
const clientCloudTasks = new CloudTasksClient({
keyFilename: "./serviceAccountKey.json",
});
3- Queue Creation Attempt: I attempted to create a queue with the following code:
const queuePath = clientCloudTasks.queuePath('my-project-id', 'europe-central2', 'my-queue-id');
const queue = {
name: queuePath,
rateLimits: {
maxDispatchesPerSecond: 1,
},
};
const request = {
parent: clientCloudTasks.locationPath('my-project-id', 'europe-central2'),
queue: queue,
};
await clientCloudTasks.createQueue(request);
Additional Details:
- I verified that the "Cloud Tasks Queue Admin" role includes the cloudtasks.queues.create permission.
- The service account is correctly configured, and the JSON key file is properly referenced in the code.
- The specified project and location exist and are correctly referenced.
Question:
Why am I receiving this permission error despite the configurations made?
roles/cloudtasks.queueAdmin
; (3) referencing a key from the Service Account in your code; (4) running the code (where?) but, at least one of these steps is incorrect. Please update your question with more details that prove your assertions so that we may help.GOOGLE_APPLICATION_CREDENTIALS=${PWD}/serviceAccountKey.json
and thenconst clientCloudTasks = new CloudTasksClient();
const keyFile = JSON.parse(fs.readFileSync("./serviceAccountKey.json")); console.log(keyFile.client_email); Result: [email protected].
2-Roles: Has roles/cloudtasks.queueAdmin with cloudtasks.queues.create. 3-Issue: PERMISSION_DENIED: The principal lacks "cloudtasks.queues.create" for "projects/XXXXXX/locations/europe-central2". Question: Could there be additional configurations I’m missing?"