DEV Community

Lucas M. Ríos
Lucas M. Ríos

Posted on

How create and upload content in Cloud Storage GCP?

🛢 Simple way to create a bucket in Cloud Storage from GCP.


🔗Related content

You can find repo related in:

🐱‍🏍GitHub

You can connect with me in:

🧬LinkedIn


Resume 🧾

All this blog is using shell.

Using SDK's Google we will use tool to manage Cloud Storage. In this blog we will create a storage and upload content in it.

For more information and potential of this, click here.


Pre-Conditions:

  • You need have installed SDK. You can do that following next steps Note: I set alias to use SDK like msdk. ---

1st - Set a name to bucket ✍️

We assign to a variable the name that will have bucket.

I use following command:

BUCKET_NAME="xlmriosx_bucket"
Enter fullscreen mode Exit fullscreen mode

2nd - Create bucket ✅

Using SDK installed with alias like msdk I use following command to create a bucket:

  • With alias:
mdsk gsutil mb -p $PROJECT_NAME -c $BUCKET_TYPE -l $REGION gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode
  • Without alias:
docker run --rm --volumes-from gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gsutil mb -p $PROJECT_NAME -c $BUCKET_TYPE -l $REGION gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

Where:
$PROJECT_NAME -> Is name of the project where you wnat instance a bucket.

$BUCKET_TYPE -> Is type of storage you want, like standard, nearline, coldline, archive.

$REGION -> Region where you want stay your storage bucket.

OUTPUT:

Creating gs://xlmriosx_bucket/...
Enter fullscreen mode Exit fullscreen mode

3rd - Verify that your bucket was created ✅

We will list buckets to verify that our bucket was created:

  • With alias:
docker run -ti --name gcloud-config gcr.io/google.com/cloudsdktool/cloud-sdk gcloud auth login
Enter fullscreen mode Exit fullscreen mode
  • Without alias:
msdk gsutil ls gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

4th - Upload content in bucket ⬆️

We can copy content to bucket with the following command:

msdk gsutil cp $DATA gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Copying file:///$DATA
[Content-Type=X]...
- [1 files][    Y.0 B/    Y.0 B]
Operation completed over 1 objects/Y.0 B.
Enter fullscreen mode Exit fullscreen mode

Where:
$DATA -> Directory or file that we want upload in the bucket.


5th - Say thanks, give like and share if this has been of help/interest 😁🖖


Top comments (0)