Cloud Storage is a flexible, scalable, and durable storage option for your virtual machine instances. You can read and write files to Cloud Storage buckets from almost anywhere, so you can use buckets as common storage between your instances, App Engine, your on-premises systems, and other cloud services.
If Cloud Storage buckets do not meet your performance and latency requirements, you can use Cloud Storage in combination with other instance storage options.
Before you begin
- If you want to use the command-line examples in this guide:
- Install or update to the latest version of the gcloud command-line tool.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Writing and reading data from Cloud Storage buckets
To write or read data from a bucket, you need to be given access to the bucket. Alternatively, you can read data from any bucket that is publicly accessible.
Write and read files from Cloud Storage buckets through the gsutil
tool or the Cloud Storage API.
gsutil
By default, the gsutil
command-line tool is installed on most virtual
machine instances that use
public images.
If your VM instance does not have the gsutil
command-line tool, you can
install gsutil
as part of the Cloud SDK.
- In the Cloud Console, go to the VM instances page.
-
In the list of virtual machine instances, click SSH in the row of
the instance that you want to connect to.
If you have never used
gsutil
on this instance before, use thegcloud
tool to set up credentials.gcloud init
Alternatively, if your instance is configured to use a service account with a Cloud Storage scope, you can skip this step.
Use the
gsutil
tool to create buckets, write data to buckets, and read data from those buckets. Optionally, you can also stream data to Cloud Storage.
API
If you configured your instance to use a service account with a Cloud Storage scope, you can use the Cloud Storage API to write and read data from Cloud Storage buckets.
- In the Cloud Console, go to the VM instances page.
-
In the list of virtual machine instances, click SSH in the row of
the instance that you want to connect to.
Install and configure a client library for your preferred language.
If necessary, follow the insert code samples to create a Cloud Storage bucket on the instance.
Follow the insert code samples to write data and read data, and include code in your app that writes and/or reads a file from a Cloud Storage bucket.
Mounting a bucket as a file system
You can use the Cloud Storage FUSE tool to mount a Cloud Storage bucket to your Compute Engine instance. The mounted bucket behaves similarly to a persistent disk even though Cloud Storage buckets are object storage.
To learn how to mount a Cloud Storage bucket on your instance, read Using Cloud Storage FUSE.