I am trying to get a Google Cloud Functions to print something from a file in a storage bucket.
I have the file stored in a bucket, an authenticated service account with Storage Admin, Cloud Run Admin, Service Account User and Cloud Functions Admin and the following python script.
def from_storage(event, context):
import json
from google.cloud import storage
client = storage.Client(project='my-project')
try:
bucket = client.get_bucket('my-storage')
except Exception as e:
print('Bucket not found.')
print(e)
try:
blob = bucket.blob('Hello_World.json')
data = json.load(blob.download_as_string())
return data
except Exception as e:
print('Error loading file:')
print(e)
I try to deploy this with the following code:
gcloud functions deploy from_storage --runtime python39 --triger-http --allow-unauthenticated
To which I get an error that the deploying service account (which seems to be an automatically created service account), does not have storage.objects.get permissions:
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: could not resolve storage source: googleapi: Error 403: [email protected] does not have storage.objects.get access to the Google Cloud Storage object., forbidden
I find this rather strange, as I do not see this service account in my IAM, nor can I access its permissions in Cloud Functions. Any help would be greatly appreciated!