Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud Run Function Fails with ENOENT: No such file or directory error

Hi everyone,

I'm currently working on a Google Cloud Function that processes CSV files uploaded to Google Cloud Storage and then loads the data into BigQuery. However, I'm encountering an ENOENT: no such file or directory error when the function tries to access the uploaded file, even though I can confirm that the file exists in the bucket and the correct path is being used.

Here's a summary of the setup and the problem:

  • Google Cloud Storage Bucket: gs://email-data-ctrl
  • File Path: The function is triggered when a CSV file is uploaded to the bucket. The file path is constructed as gs://email-data-ctrl/[file_name].csv.
  • Cloud Function Role: The service account for my Cloud Function has the roles/storage.objectViewer permission on the bucket.
  • IAM Roles: I’ve confirmed that the service account has the correct IAM permissions, including roles/storage.objectViewer for Cloud Storage.

Despite all this, the function is still returning the following error in the logs:

Error: ENOENT: no such file or directory, open 'gs://email-data-ctrl/[file_name].csv'

Here’s what I’ve tried so far:

  • Verified that the file exists using gsutil ls.
  • Checked the permissions using gsutil iam get.
  • Ensured the function has the proper IAM permissions for accessing the bucket.

Has anyone encountered a similar issue with Cloud Functions accessing Cloud Storage, and if so, how did you resolve it? Any advice or troubleshooting steps would be greatly appreciated.

Thanks in advance for your help!

menbitame_0-1729483871258.png

 

0 1 613
1 REPLY 1

Hi @menbitame,

Welcome to Google Cloud Community!

It looks like the ENOENT error could be caused by either a slight delay in the file being available when the Cloud Function triggers or a mismatch in the file path. Even though the file exists, there might be a timing issue or a small problem in how the path is constructed.

Here’s what you can try:

  1. Add a short delay or retry logic in your function to ensure the file is fully uploaded before accessing it.
  2. Double-check that the file path in the function is formatted correctly.
  3. Verify your Cloud Function’s service account has both roles/storage.objectViewer and possibly roles/storage.objectAdmin.

I hope the above information is helpful.