Reputation: 11
I have created a service account in the GCP IAM services, and then, I've granted the permissions storage.buckets.create
, storage.buckets.get
and storage.buckets.list
to the service account. After that, I've managed to authorize the credentials.
But when I try to create a bucket I see the following error:
@cloud-functions-intro.iam.gserviceaccount.com does not have storage.buckets.create access to project
The code is like this:
const projectId = 'cloud-functions-intro';
const bucketName = `${projectId}-packaging-data`;
const storage = new Storage({
projectId: projectId,
keyFilename: 'my_credentials.json'
});
const bucket = storage.bucket(bucketName);
Upvotes: 1
Views: 751
Reputation: 964
I did a test myself and I was able to do it following the snippet code of the documentation, but pointing to the keyfile as you are doing:
const {Storage} = require('@google-cloud/storage');
const projectId = 'project_id';
const storage = new Storage({
projectId: projectId,
keyFilename: 'credentials.json'
});
const bucketName = 'bucket_name';
storage
.createBucket(bucketName)
.then(() => {
console.log(`Bucket ${bucketName} created.`);
})
.catch(err => {
console.error('ERROR:', err);
});
This should work. If you keep getting the same error then my recommendation is to furnish a new key for that service account and be 100% sure the keyfile you are passing is the correct one.
Upvotes: 1