functions-samples: Deploy Error: Failed to configure trigger GCS Bucket
Hi, I’m trying out the image resizing demo. Deployment throwing error:
Deploy Error: Failed to configure trigger GCS Bucket: product_images
My images are inside product_images
folder and my code looks like this:
exports.generateThumbnail = functions.storage.object().onChange(event => {
const object = event.data;
const fileBucket = object.bucket;
const filePath = object.name;
const contentType = object.contentType;
const resourceState = object.resourceState;
if(!filePath.match(/product_images/)) {
console.log('not product_images bucket');
return;
}
if (!contentType.startsWith('image/')) {
console.log('This is not an image.');
return;
}
const fileName = filePath.split('/').pop();
// Exit if the image is already a thumbnail.
if (fileName.startsWith('thumb_')) {
console.log('Already a Thumbnail.');
return;
}
if (resourceState === 'not_exists') {
console.log('This is a deletion event.');
return;
}
const bucket = gcs.bucket(fileBucket);
const tempFilePath = `/tmp/${fileName}`;
return bucket.file(filePath).download({
destination: tempFilePath
}).then(() => {
console.log('Image downloaded locally to', tempFilePath);
// Generate a thumbnail using ImageMagick.
return spawn('convert', [tempFilePath, '-thumbnail', '64x64>', tempFilePath]).then(() => {
console.log('Thumbnail created at', tempFilePath);
// We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, `$1thumb_$2`);
// Uploading the thumbnail.
return bucket.upload(tempFilePath, {
destination: thumbFilePath
});
});
});
});
Not sure what it means.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 21 (8 by maintainers)
I was having the same problem. Apparently it is caused by missing permission on service account executing cloud function.
I just added
Storage Object Admin
role to default to default service account and everything start to work as expected.FYI this issue is somewhat widespread because we used to have a bug (as of 1-2 month ago) where lots of Cloud Storage Buckets were created with the wrong permissions. New projects don’t have this issue but if you have an old Firebase project which is impacted by this the manual fix for your permissions is described here:
https://github.com/firebase/friendlychat/issues/184#issuecomment-290914672
For posterity: Cloud Functions requires editor permission on your project.