This page shows you how to add, modify, remove, and view the labels set on a bucket in Cloud Storage.
Required roles
In order to get the required permissions for adding and managing bucket labels,
ask your administrator to grant you the Storage Admin
( roles/storage.admin
) IAM role on the bucket.
This predefined role contains the permissions required to add and manage bucket labels. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
-
storage.buckets.get
-
storage.buckets.list
- This permission is only required if you plan on using the Google Cloud console to perform the instructions on this page.
-
storage.buckets.update
You might also be able to get these permissions with custom roles .
For instructions on granting roles on buckets, see Use IAM with buckets .
Add, modify, or remove a bucket's labels
Console
- In the Google Cloud console, go to the Cloud Storage Buckets
page.
-
In the list of buckets, click the name of the bucket for which you want to add, modify, or remove labels.
-
In the Bucket detailspage, click the Configurationtab.
-
Click the Editicon ( edit ) for Labels.
The label editor window appears.
-
To add a label, click the add_box Add labelbutton, and specify a
key
and avalue
for your label. -
To modify an existing label, click its Valueand a enter a new value.
-
To remove a label, click the Trash iconassociated with the label you want to remove.
-
-
Click Save.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, see Troubleshooting .
Command line
To add a new label or update an existing label, use the gcloud storage buckets update
command with the --update-labels
flag. For example:
gcloud storage buckets update gs:// BUCKET_NAME --update-labels= KEY_1 = VALUE_1
Where
-
BUCKET_NAME
is the name of the bucket that the label applies to. For example,my-bucket
. -
KEY_1
is the key name for your label. For example,pet
. -
VALUE_1
is the value for your label. For example,dog
.
To remove an existing label, use the -remove-labels
flag. For example:
gcloud storage buckets update gs:// BUCKET_NAME --remove-labels= KEY_1
You can change multiple labels using the previous commands by including the
labels in a comma-separated list within the relevant flag. For example, --update-labels=blue-key=cyan,red-key=ruby
.
To remove all labels attached to a bucket, use the following command:
gcloud storage buckets update gs:// BUCKET_NAME --clear-labels
Client libraries
C++
For more information, see the Cloud Storage C++ API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
C#
For more information, see the Cloud Storage C# API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
Go
For more information, see the Cloud Storage Go API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
Java
For more information, see the Cloud Storage Java API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
Node.js
For more information, see the Cloud Storage Node.js API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
PHP
For more information, see the Cloud Storage PHP API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
Python
For more information, see the Cloud Storage Python API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket:
Ruby
For more information, see the Cloud Storage Ruby API reference documentation .
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries .
The following sample adds the specified label to a bucket, or modifies the label if it already exists for the bucket:
The following sample removes the specified label from a bucket: