Connecting to Cloud Storage buckets

Google 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, Google 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

Writing and reading data from Google 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 Google 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 Google Cloud SDK.

  1. Connect to an instance.

    1. In the GCP Console, go to the VM Instances page.

      Go to the VM Instances page

    2. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.

  2. If you have never used gsutil on this instance before, use the gcloud tool to set up credentials.

    gcloud init

    Alternatively, if your instance is configured to use a service account with a Google Cloud Storage scope, you can skip this step.

  3. 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 Google Cloud Storage scope, you can use the Cloud Storage APIs to write and read data from Cloud Storage buckets.

  1. Connect to an instance.

    1. In the GCP Console, go to the VM Instances page.

      Go to the VM Instances page

    2. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.

  2. Install and configure a client library for your preferred language.

  3. If necessary, follow the insert code samples to create a Cloud Storage bucket on the instance.

  4. Follow the insert code samples to write data and read data, and include code in your application that writes and/or reads a file from a Cloud Storage bucket.

Mounting a bucket as a file system

You can use the Google 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.

Was this page helpful? Let us know how we did:

Send feedback about...

Compute Engine Documentation