This page shows you how to enable, disable, and check the status of the
Autoclass feature, which is set on a bucket in Cloud Storage.
Required roles
To get the permissions that you need to set and manage Autoclass on a bucket,
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 set and manage Autoclass on a bucket. To see the
exact permissions that are required, expand the Required permissions
section:
Required permissions
storage.buckets.get
storage.buckets.list
This permission is only required for using the Google Cloud console
to perform the tasks on this page.
storage.buckets.update
You can also get these permissions with custom roles.
In the list of buckets, click the name of the desired bucket.
In the Bucket details page, click the Configuration tab.
Click the Edit icon
(edit)
for Default storage class.
In the overlay window, select Autoclass to enable Autoclass. To
disable Autoclass, select Set a default class, and then select a
default storage class for the bucket.
Click Confirm.
To switch the terminal storage class for a bucket that has Autoclass
enabled, click the Edit icon
(edit)
for Included classes, and click Confirm in the overlay window
that appears.
BUCKET_NAME is the name of the relevant
bucket. For example, my-bucket.
DEFAULT_CLASS sets the storage class
metadata for the bucket. When enabling Autoclass, STANDARD is
the only valid value and is required if the bucket currently uses
a different storage class.
AUTOCLASS_FLAG is one of the following:
--enable-autoclass to enable Autoclass.
--no-enable-autoclass to disable Autoclass.
--autoclass-terminal-storage-class=CLASS
to set the terminal storage class for Autoclass. CLASS
can be either NEARLINE or ARCHIVE. When using this flag on a
bucket with Autoclass disabled, also include the --enable-autoclass
flag in the command.
If successful, the response looks similar to the following example:
namespacegcs=::google::cloud::storage;[](gcs::Clientclient,std::stringconst&bucket_name,boolenabled){autometadata=client.PatchBucket(bucket_name,gcs::BucketMetadataPatchBuilder().SetAutoclass(gcs::BucketAutoclass{enabled}));if(!metadata)throwgoogle::cloud::Status(std::move(metadata).status());std::cout << "The autoclass configuration for bucket " << bucket_name << " was successfully updated.";if(!metadata->has_autoclass()){std::cout << " The bucket no longer has an autoclass configuration.\n";return;}std::cout << " The new configuration is " << metadata->autoclass() << "\n";}
usingGoogle.Cloud.Storage.V1;usingGoogle.Apis.Storage.v1.Data;usingstaticGoogle.Apis.Storage.v1.Data.Bucket;usingSystem;publicclassSetAutoclassSample{publicBucketSetAutoclass(stringbucketName){varstorage=StorageClient.Create();varbucket=storage.GetBucket(bucketName);bucket.Autoclass=newAutoclassData{Enabled=true,TerminalStorageClass="ARCHIVE"};storage.PatchBucket(bucket);Console.WriteLine($"Autoclass enabled is set to {bucket.Autoclass.Enabled} for {bucketName} at {bucket.Autoclass.ToggleTimeDateTimeOffset}.");Console.WriteLine($"Autoclass terminal storage class is {bucket.Autoclass.TerminalStorageClass}.");returnbucket;}}
import("context""fmt""io""time""cloud.google.com/go/storage")// setAutoclass sets the Autoclass configuration for a bucket.funcsetAutoclass(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"// To update the configuration for Autoclass.TerminalStorageClass,// Autoclass.Enabled must also be set to true.// To disable autoclass on the bucket, set to an empty &Autoclass{}.enabled:=trueterminalStorageClass:="ARCHIVE"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()bucket:=client.Bucket(bucketName)bucketAttrsToUpdate:=storage.BucketAttrsToUpdate{Autoclass:&storage.Autoclass{Enabled:enabled,TerminalStorageClass:terminalStorageClass,},}if_,err:=bucket.Update(ctx,bucketAttrsToUpdate);err!=nil{returnfmt.Errorf("Bucket(%q).Update: %w",bucketName,err)}fmt.Fprintf(w,"Autoclass enabled was set to %v on bucket %q \n",bucketAttrsToUpdate.Autoclass.Enabled,bucketName)fmt.Fprintf(w,"Autoclass terminal storage class was last updated to %v at %v",bucketAttrsToUpdate.Autoclass.TerminalStorageClass,bucketAttrsToUpdate.Autoclass.TerminalStorageClassUpdateTime)returnnil}
importcom.google.cloud.storage.Bucket;importcom.google.cloud.storage.BucketInfo.Autoclass;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.Storage.BucketTargetOption;importcom.google.cloud.storage.StorageClass;importcom.google.cloud.storage.StorageOptions;publicclassSetBucketAutoclass{publicstaticvoidsetBucketAutoclass(StringprojectId,StringbucketName,StorageClassstorageClass)throwsException{// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";// The storage class that objects in an Autoclass bucket eventually transition to if not read// for a certain length of time// StorageClass storageClass = StorageClass.ARCHIVE;// Configure the Autoclass setting for a bucket.// Note: terminal_storage_class field is optional and defaults to NEARLINE if not otherwise// specified. Valid terminal_storage_class values are NEARLINE and ARCHIVE.booleanenabled=true;try(Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService()){Bucketbucket=storage.get(bucketName);BuckettoUpdate=bucket.toBuilder().setAutoclass(Autoclass.newBuilder().setEnabled(enabled).setTerminalStorageClass(storageClass).build()).build();Bucketupdated=storage.update(toUpdate,BucketTargetOption.metagenerationMatch());System.out.println("Autoclass for bucket "+bucketName+" was "+(updated.getAutoclass().getEnabled()?"enabled.":"disabled."));System.out.println("Autoclass terminal storage class is "+updated.getAutoclass().getTerminalStorageClass().toString());}}}
/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// The terminal storage class to be set on your GCS bucket. Valid values are NEARLINE and ARCHIVE.// const terminalStorageClass = 'NEARLINE';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctionsetAutoclass(){// Configure the Autoclass setting for a bucket.// terminalStorageClass field is optional and defaults to NEARLINE if not otherwise specified.// Valid terminalStorageClass values are NEARLINE and ARCHIVE.const[metadata]=awaitstorage.bucket(bucketName).setMetadata({autoclass:{enabled:toggle,terminalStorageClass,},});console.log(`Autoclass terminal storage class is ${metadata.autoclass.terminalStorageClass}.`);}setAutoclass().catch(console.error);
fromgoogle.cloudimportstoragedefset_autoclass(bucket_name):"""Configure the Autoclass setting for a bucket. terminal_storage_class field is optional and defaults to NEARLINE if not otherwise specified. Valid terminal_storage_class values are NEARLINE and ARCHIVE. """# The ID of your GCS bucket# bucket_name = "my-bucket"# Enable Autoclass for a bucket. Set enabled to false to disable Autoclass.# Set Autoclass.TerminalStorageClass, valid values are NEARLINE and ARCHIVE.enabled=Trueterminal_storage_class="ARCHIVE"storage_client=storage.Client()bucket=storage_client.bucket(bucket_name)bucket.autoclass_enabled=enabledbucket.autoclass_terminal_storage_class=terminal_storage_classbucket.patch()print(f"Autoclass enabled is set to {bucket.autoclass_enabled} for {bucket.name} at {bucket.autoclass_toggle_time}.")print(f"Autoclass terminal storage class is {bucket.autoclass_terminal_storage_class}.")returnbucket
require"google/cloud/storage"### This is a snippet for showcasing how to set the autoclass# configuration of a bucket.## @param bucket_name [String] The ID of your GCS bucket (e.g. "your-unique-bucket-name")# @param toggle [Boolean] if true, enables Autoclass; if false, disables Autoclass#defset_autoclassbucket_name:,toggle:,terminal_storage_class:nil# Initialize clientstorage=Google::Cloud::Storage.new# Fetch the GCS bucketbucket=storage.bucketbucket_name# Update the autoclass configurationbucket.update_autoclass({enabled:toggle,terminal_storage_class:terminal_storage_class})terminal_class_update_time=bucket.autoclass_terminal_storage_class_update_time# Get autoclass config of the bucketputs"Bucket #{bucket.name} has autoclass config set to #{bucket.autoclass_enabled}."puts"Bucket #{bucket.name} has autoclass toggle time set to #{bucket.autoclass_toggle_time}."puts"Bucket #{bucket.name} has autoclass terminal storage class set to #{bucket.autoclass_terminal_storage_class}."puts"Bucket #{bucket.name} has autoclass terminal storage class update time set to #{terminal_class_update_time}."end
Rust
usegoogle_cloud_storage::client::StorageControl;usegoogle_cloud_storage::model::bucket::Autoclass;usegoogle_cloud_wkt::FieldMask;pubasyncfnsample(client:&StorageControl,bucket_id:&str)->anyhow::Result<()>{letbucket=client.get_bucket().set_name(format!("projects/_/buckets/{bucket_id}")).send().await?;letmetageneration=bucket.metageneration;letbucket=client.update_bucket().set_bucket(bucket.set_autoclass(Autoclass::new().set_enabled(true))).set_if_metageneration_match(metageneration).set_update_mask(FieldMask::default().set_paths(["autoclass"])).send().await?;println!("successfully updated autoclass for bucket {bucket_id}: {:?}",bucket.autoclass);Ok(())}
Click the name of the bucket whose status you want to check.
Click the Configuration tab.
The status for Autoclass is displayed in the Default storage class
field.
If Autoclass is enabled, the field reads Managed with Autoclass,
and the Included classes field displays the storage classes that
objects can transition between.
usingGoogle.Cloud.Storage.V1;usingSystem;usingstaticGoogle.Apis.Storage.v1.Data.Bucket;publicclassGetAutoclassSample{publicAutoclassDataGetAutoclass(stringbucketName){varstorage=StorageClient.Create();varbucket=storage.GetBucket(bucketName);Console.WriteLine($"Autoclass enabled is set to {bucket.Autoclass.Enabled} for {bucketName} at {bucket.Autoclass.ToggleTimeDateTimeOffset}.");Console.WriteLine($"Autoclass terminal storage class is set to {bucket.Autoclass.TerminalStorageClass} for {bucketName} at {bucket.Autoclass.TerminalStorageClassUpdateTimeDateTimeOffset}.");returnbucket.Autoclass;}}
import("context""fmt""io""time""cloud.google.com/go/storage")// getAutoclass gets the Autoclass configuration for a bucket.// See https://cloud.google.com/storage/docs/using-autoclass for more information.funcgetAutoclass(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()ctx,cancel:=context.WithTimeout(ctx,time.Second*10)defercancel()attrs,err:=client.Bucket(bucketName).Attrs(ctx)iferr!=nil{returnfmt.Errorf("Bucket(%q).Attrs: %w",bucketName,err)}fmt.Fprintf(w,"Autoclass enabled was set to %v on bucket %q at %v",attrs.Autoclass.Enabled,bucketName,attrs.Autoclass.ToggleTime)fmt.Fprintf(w,"Autoclass terminal storage class was last updated to %v at %v",attrs.Autoclass.TerminalStorageClass,attrs.Autoclass.TerminalStorageClassUpdateTime)returnnil}
importcom.google.cloud.storage.BucketInfo.Autoclass;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageClass;importcom.google.cloud.storage.StorageOptions;importjava.time.OffsetDateTime;publicclassGetBucketAutoclass{publicstaticvoidgetBucketAutoclass(StringprojectId,StringbucketName){// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();Autoclassautoclass=storage.get(bucketName).getAutoclass();Stringstatus=autoclass.getEnabled()?"enabled":"disabled";StringtoggleTime=autoclass.getToggleTime().toString();StorageClassterminalStorageClass=autoclass.getTerminalStorageClass();OffsetDateTimeterminalStorageClassUpdateTime=autoclass.getTerminalStorageClassUpdateTime();System.out.println("Autoclass is currently "+status+" for bucket "+bucketName+" and was last changed at "+toggleTime+". The terminal storage class is set to be "+terminalStorageClass.name()+" last updated at "+terminalStorageClassUpdateTime.toString());}}
/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctiongetAutoclass(){const[metadata]=awaitstorage.bucket(bucketName).getMetadata();console.log(`Autoclass is ${metadata.autoclass.enabled?'enabled':'disabled'} for ${metadata.name} at ${metadata.autoclass.toggleTime}. Autoclass terminal storage class is last updated to ${metadata.autoclass.terminalStorageClass} at ${metadata.autoclass.terminalStorageClassUpdateTime}.`);}getAutoclass().catch(console.error);
require"google/cloud/storage"### This is a snippet for showcasing how to access the autoclass# configuration of a bucket.## @param bucket_name [String] The ID of your GCS bucket (e.g. "your-unique-bucket-name")#defget_autoclassbucket_name:# Initialize clientstorage=Google::Cloud::Storage.new# Fetch the GCS bucketbucket=storage.bucketbucket_nameterminal_class_update_time=bucket.autoclass_terminal_storage_class_update_time# Get autoclass config of the bucketputs"Bucket #{bucket.name} has autoclass config set to #{bucket.autoclass_enabled}."puts"Bucket #{bucket.name} has autoclass toggle time set to #{bucket.autoclass_toggle_time}."puts"Bucket #{bucket.name} has autoclass terminal storage class set to #{bucket.autoclass_terminal_storage_class}."puts"Bucket #{bucket.name} has autoclass terminal storage class update time set to #{terminal_class_update_time}."end
Rust
usegoogle_cloud_storage::client::StorageControl;pubasyncfnsample(client:&StorageControl,bucket_id:&str)->anyhow::Result<()>{letbucket=client.get_bucket().set_name(format!("projects/_/buckets/{bucket_id}")).send().await?;println!("Autoclass for bucket {bucket_id}: {:?}",bucket.autoclass);Ok(())}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-06-09 UTC."],[],[]]