Lesson 6.2: Create Blob Storage Container

Azure Blob Storage is an option for saving raw files in containers that can be retrieved and read in our services. We can use a storage account and container to hold our data files. They can be updated by tools, uploaded by the operations team, or edited in Azure directly. Then, the data becomes available to our service.

Using Blob storage is another level of isolation from having the files as embedded resources. The data can be updated and added without requiring a new release of the game services. If our service logic doesn’t change often, it makes it easier in the cases where we just want to update the game content.

In this lesson we are going through the steps to set up the container and upload our data files. These will include configuration and screenshots for how to do this. The Azure UI tends to change, but we will try to keep these images accurate with the latest versions of the Azure Portal.

Game Files in Storage Container

First, we need to setup an Azure Storage account and container to hold our game files.

  1. Let’s start in the Azure portal: https://portal.azure.com.
  2. Since we already have a storage account for our SimpleRPG game, we will use that one.
  3. Navigate to the ‘simplerpgv2’ storage account (we created this in Lesson 5.16).
Fig 1 – simplerpgv2 Storage Account
  1. In the left navigation panel, select the ‘Containers’ item (in the Blob Service section). We are creating a blob storage container for our game data files.
Fig 2 – Storage Account Container List
  1. Click the ‘New Container’ button in the toolbar. Containers are like root folders in our blob storage. We can provide different access keys per container for different applications and services.
Fig 3 – Name New Container
  1. Name the new container ‘game-data’, and keep the remaining defaults in the flyout. (the image shows a name collision because we had previously created this container, you shouldn’t see that).
  2. Click the ‘Create’ button. This will create the new container, and we can see it in the list.
Fig 4 – Click game-data Container
  1. Click the ‘game-data’ container in the list to open its viewer. The container starts out empty.
  2. Let’s add our game data files to this container by clicking the ‘Upload’ button in the toolbar.
  3. In the ‘Blob upload’ flyout, click the folder icon to launch the system file picker dialog.
Fig 5 – Upload Blob Flyout
  1. In that dialog, navigate to our data folder, select all of the files, and click the ‘Open’ button.
Fig 6 – File Open Dialog
  1. We return to the flyout, which now shows the list of files to be uploaded.
  2. Click the ‘Upload’ button and wait for the files to complete.
  3. In the ‘game-data’ viewer, we will now see our 6 data files.
Fig 7 – Container With Data Files
  1. We have successfully placed our data files into our Blob storage container.

Editing Container Files

With the files there, we will be able to write code to access those files from our SimpleRPG.Game.Services. Before we do that, let’s change the data a little to make sure we are loading from the right source. This will also show us how users with Azure access can update the game data directly.

  1. In the ‘game-data’ container viewer (where we left off from the previous section), click on the ‘items.json’ file.
Fig 8 – items.json File Properties
  1. In the file properties view, we see lots of useful information about the file (modified date, size, content type, etc).
  2. Switch to the ‘Edit’ tab for this file.
  3. We see json layout for the items file content. We can also edit the information in the file from this view.
Fig 9 – Edited Json File
  1. Let’s update the first item to ‘Pointy stick – blob’. This way we will know that we are retrieving item data from blob storage when we load it in the web services or see it in the game screen.

Azure gives us a simple tool to make changes to files in Blob storage. It works great for json or plain text files, but not useful for binary or encrypted data. And, it also means only team members with contributor access to Azure can make these changes. But, it is useful for quick changes and fixes.

Connection String

For our service to read data from this storage account, we will need to retrieve its connection string and access token. Typically we would keep this connection string as a secret or in Azure KeyVault to keep it secure. But for this sample we will copy it into our source tree (it is only the read access token and connection string).

  1. Navigate back to the root of the ‘simplerpgv2’ storage account.
Fig 10 – Back to simplerpgv2 Storage Account
  1. In the navigation panel, click the ‘Access Keys’ item.
  2. In the page, click the ‘Show Keys’ button to let us see the key and connection string.
Fig 11 – Access Keys Hidden
  1. Copy the connection string. Save that connection string for use in the next lesson when we build the Blob storage repository.
Fig 12 – Access Keys Shown

This concludes all of the Azure setup and configuration required to create and expose our ‘game-data’ blob container. We filled that container with the same data files that we used previously. And made a minor item name change to validate that we are getting items from our expected data source. In the next lesson we will focus on building a new repository that loads its data from this storage container.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s