Cloud Storage Options Part 1

By January 31, 2017.NET, Cloud Platform, Google
For any .NET developer looking to integrate with Google Cloud, one of the most basic decisions will be what Google Cloud Storage options make sense for you? When you think cloud storage, don’t just think blob storage, because Google Cloud Platform storage is really much more diverse than that, from basic blob to fully managed MySQL services to different flavors of NoSQL.

Storage Options

If you already have an application on another cloud service provider and are moving to Google Cloud, you likely already know what kind of storage you need and how often you’ll be accessing it. You’ll want to start by taking a look at a comparison map and finding the equivalent storage options within GCP. Google’s extensive documentation can make that easier if you are considering migrating from Azure or Amazon, so use those resources to help you decide. You’ll also want to compare pricing, especially if your storage needs are sizable.
But if you are starting from scratch or moving a non-cloud based app to Google Cloud, you have some decisions to make. For me, it’s always more interesting to start with an example! So let’s look at how a .NET developer can easily set up and interact with the different offerings of Google Cloud Storage.

First Steps

Before you get started, there are a couple of pieces you need to have ready:
 a GCP Project already created to house our storage examples
 a version of Visual Studio to run a C# sample project. If you don’t have one, go grab the Community edition

Structured vs Unstructured

Google Cloud Storage options include both structured and unstructured data. You may be used to just thinking of unstructured blob data as cloud storage, but if you consider all stored information to be “cloud data”, then of course structured data can be considered “Storage” also. Think of it this way: if you want the data to have rows and/or columns, then it is structured. In parts 1 and 2 of this post, we will take a look at both kinds, starting with unstructured. Then we will look at the 3 main types of structured data storage.

Google Cloud Storage

This is unstructured blob storage as you probably already are familiar with. Just as when you create a storage container in Azure, creating a storage container in Google Cloud Storage requires that you select a few options, taking into account the reliability, access frequency, and access speed that you will need. Get used to Google’s storage terminology – Buckets are the containers for your Objects, in Google-speak.
First create a Bucket. If you already know the configuration you’ll need, you will probably prefer to do this using the gCloud command line utility, but for an initial look it is nice to see all of the options using the Console.
 
Start by navigating to Storage in the Console menu, then choose Create Bucket.
To create a multiregional bucket using gcloud use the mb command:
Once your bucket is created it is ready to start storing objects, which you can do through the console, even at the folder-level if you use Chrome.
Since we are .NET developers, let’s do an upload using C#!

Credentials

First, we need to enable some sort of authentication to our Google Cloud Storage. We aren’t using any user data, so we will use Application Default Credentials. And to make things even easier, we can set those up for our development environment with a single gcloud command.
Note that we are using a beta command, and so you may need to run as an administrator and install the beta commands – don’t worry, you will be prompted automatically if that is the case.
The auth command will open a browser window for you to allow authentication, and allow you to use those credentials as a proxy for application credentials for development.
Note: You can access all of the code for this C# example from the github repository.

C# Operations

Using the .NET storage library, it is very straightforward to create a bucket:
And to perform an upload:
The github link above will take you to a C# console app that can perform these operations.

And we can see the uploaded documents using the Console as well.

Google Cloud SQL

Google Cloud SQL is our first structured Cloud storage option. This is your full-featured MySQL database service, for relational data in the cloud, managed by Google. If you come from a .NET background and aren’t familiar with MySQL, you may want to read up on it to get started https://cloud.google.com/sql/. MySQL is the most popular open-source, cross-platform relational database, and it is the relational-data storage mechanism of choice for Google itself, as well as well-known heavy hitters like Facebook and Adobe. If you are “all-in” with Google Cloud, take a good look at MySQL, because you will probably find the most experience, documentation, and integrations with the rest of Google Cloud start with Google Cloud SQL.
To create a Cloud SQL Instance, navigate to the SQL option in the GCP Console and choose Create instance.
    
 I’m selecting the Second Generation option.
You can add a name and leave the default selections, then choose Create. Or, you can use this gcloud command:
Using either method, you should now be able to see the new instance in the Console.
 
Keeping with our .NET theme, I’ll also show you how to connect to the new Google Cloud SQL instance using Visual Studio.

First Steps

Here’s what you’ll need:
Using the Cloud Tools Google Cloud Explorer, you should be able to see the instance under the Google Cloud SQL heading.
But before we can connect, we need to allow connections from our development machine. The following gcloud commands will add a single IP address to the authorized networks list (use your local IP to connect from your local machine), and set the root user’s password, where instance1 is the Cloud SQL instance name.
You can learn more about the patch and other instance commands here.
Once your IP address is allowed, you can use the root user and the password you just created to add a connection in Visual Studio, just as you would for any other database.
Now you will see the instance inside Visual Studio’s Server Explorer. Just to show that we can – let’s add a table with an int column, by right clicking and creating a new query with the text
Now you can see the table and column in Visual Studio’s Server Explorer as well.
Of course if you don’t like Visual Studio, any IDE that works with MySQL will work, including the MySQL Command line Tool.
But if you DO like Visual Studio, and you’d like to see this example continued to show how to use Entity Framework with your new Google Cloud SQL instance, check out this other post in our series.
In Part 2 of this post, we will look at 2 more Cloud Storage options – Google BigTable and Google DataStore.

Other Resources

The following two tabs change content below.