0
votes

I've been trying to create buckets in Google Cloud Storage following the guidelines from this link, using Java. I have a method that checks whether a bucket exists or not and returns a boolean, like this

private boolean checkIfBucketExists(String bucketName) {
   return storage.get(bucketName, Storage.BucketGetOption.fields()) != null
}

And, another method that actually creates a bucket, like this

public Bucket createBucket(String bucketName) {
    if (checkIfBucketExists(bucketName)) {
      System.out.println("Bucket already exists!");
    }
    return storage.create(
        BucketInfo.newBuilder(bucketName)
            // See here for possible values: http://g.co/cloud/storage/docs/storage-classes
            .setStorageClass(StorageClass.COLDLINE)
            // Possible values: http://g.co/cloud/storage/docs/bucket-locations#location-mr
            .setLocation("eu")
            .build());
  }

It acts a little weird sometimes when I'm creating a bucket. For example, I'm able to create a bucket named name-bucket, but not namebucket, even though I don't have an existing namebucket in my project. It gives me this error

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "[email protected] does not have storage.buckets.get access to namebucket.",
    "reason" : "forbidden"
  } ],
  "message" : "[email protected] does not have storage.buckets.get access to namebucket."
}

Is it so that, in Google Cloud Storage, I cannot create a bucket using a name that has been chosen by another user in their project? Is the reason why I cannot choose the name namebucket because someone else has already named a bucket like so in their project?

1

1 Answers

2
votes

Yes, the bucket names are unique for all users.

Check the Documentation for bucket name considerations:

Bucket names reside in a single Cloud Storage namespace, which means that every bucket name must be unique. If you try to create a bucket with a name that is already assigned to an existing bucket, Cloud Storage responds with an error message. However, once you delete a bucket, its name can be reused by you or another user when creating a new bucket.