kennemat
kennemat

Reputation: 190

GCP Cloud Function gets 403 when calling get_bucket for GCS

I have a cloud function with the basic code below that is trying to get blobs in a gcs bucket.

import base64
import json
import functions_framework

from google.cloud import bigquery
from google.cloud import storage

# Triggered from a message on a Cloud Pub/Sub topic.
@functions_framework.cloud_event
def hello_pubsub(cloud_event):
    storage_client = storage.Client()

    bucket = storage_client.get_bucket(some_bucket)
    blobs = bucket.list_blobs(prefix=file, delimiter='/')
    print(blobs)

However, after the function runs, I get a 403 error with message google.api_core.exceptions.Forbidden: 403 GET https://storage.googleapis.com/storage/v1/b/aRandomBucket?projection=noAcl&prettyPrint=false: [email protected] does not have storage.buckets.get access to the Google Cloud Storage bucket. Permission 'storage.buckets.get' denied on resource (or it may not exist)."

I have given my cloud function service account Storage Admin and custom roles that include storage.buckets.get permission for accessing storage, and I've gone as far as opening the bucket to the public, but I still get a 403.

Below are images of the service account details - the CloudFuncsStorageAndBQ role just has `storage.buckets.get Picture of cloud function details

Picture of service account in IAM

Upvotes: 1

Views: 775

Answers (1)

kennemat
kennemat

Reputation: 190

Solved - for anyone else who is struggling with this, I was using the wrong string for the bucket name, so I was accessing a bucket that didn't exist.

Upvotes: 0

Related Questions