Getting Started with Storage in Azure Government


Azure Government uses the same underlying technologies as commercial Azure, enabling you to use the development tools you’re already familiar with. However, Azure Government provides a physical and network-isolated instance of Azure which results in a higher level of compliance and security. As a result of this, we use different physical endpoints for our services such as Azure Storage. Getting started with Storage on Azure Government is quite easy.

The Microsoft Azure Storage Explorer has quickly become one of the most popular tools for working with Azure Storage. It is cross-platform and free. We are happy to announce the accessibility of Azure Government through the Azure Storage Explorer as of the 0.8.9 release. Government customers will now be able to take advantage of all the latest features of the Azure Storage Explorer such as being able to create and manage blobs, queues, tables, and file shares.

When you open the Azure Storage Explorer desktop application it will ask you how you want to connect to your storage account. The newest version will now give you the option to add an “Azure US Government” account:

1

Once you’re logged in, the Azure Storage Explorer enables you to quickly and easily see the resources inside your storage account. In the screenshot below, you can see my storage account named “samplegovstorageacct” which has a blob container, a storage queue, and a storage table called “Contacts”. With a quick double-click, we can see the contents of our Contacts table:

2

Check out the full list of features and download the latest version of the Microsoft Azure Storage Explorer on their home page here.

The Azure Storage Explorer is great for quickly connecting to your storage accounts. However, for the keen observers, you noticed that in the last screenshot the URL for our storage looked a little different than the URL for storage in commercial Azure – specifically, the domain ended with “core.usgovcloudapi.net”, rather than “core.windows.net”. These endpoint differences must be taken into account when you connect to storage in Azure Government with C#.

Let see this in action. First, let’s go to the Azure Government portal and select our “samplegovstorageacct” and then click the “Access Keys” tab:

3

From here we can copy/paste the storage account name and key. For the simplicity of the sample code, I’ll just paste them into variables – but these values can be stored in Azure Key Vault (which is available on Azure Government) for maximum security.

Next let’s create a new project in Visual Studio and add a reference to the WindowsAzure.Storage NuGet package. This NuGet package contains classes we will need to connect.

Now it’s just a simple matter of 2 lines of C# code to connect:

var credentials = new StorageCredentials(storageAccountName, storageAccountKey);

var storageAccount = new CloudStorageAccount(credentials, “core.usgovcloudapi.net”, useHttps: true);

Notice on the second line we had to use a particular constructor for the CloudStorageAccount – enabling us to explicitly pass in the endpoint suffix of “core.usgovcloudapi.net”. This constructor is the only difference your code requires to connect to storage in Azure Government as compared with commercial Azure.

At this point, we can interact with storage as we normally would. For example, if we want to retrieve a specific record from our table storage we could do it like this:

var tableClient = storageAccount.CreateCloudTableClient();

var table = tableClient.GetTableReference(“Contacts”);

var retrieveOperation = TableOperation.Retrieve<ContactEntity>(“gov-partition1”, “0fb52a6c-3784-4dc5-aa6d-ecda4426dbda”);

var result = await table.ExecuteAsync(retrieveOperation);

var contact = result.Result as ContactEntity;

Console.WriteLine($”Contact: {contact.FirstName} {contact.LastName}”);

We welcome your comments and suggestions to help us continually improve your Azure Government experience. To stay up to date on all things Azure Government, be sure to subscribe to our RSS feed and to receive emails, click “Subscribe by Email!” on the Azure Government Blog. To experience the power of Azure Government for your organization, sign up for an Azure Government Trial.

Comments (0)

Skip to main content