The course is part of these learning pathsSee 5 more
Getting the Most From Azure Storage
The Azure Storage suite of services form the core foundation of much of the rest of the Azure services ecosystem. Blobs are low-level data primitives that can store any data type and size. Tables provide inexpensive, scalable NoSQL storage of key/value data pairs. Azure queues provide a messaging substrate to asynchronously and reliably connect distinct elements of a distributed system. Azure files provide an SMB-compatible file system for enabling lift-and-shift scenarios of legacy applications that use file shares. Azure disks provide consistent, high-performance storage for virtual machines running in the cloud.
In this Introduction to Azure Storage course you'll learn about the features of these core services, and see demonstrations of their use. Specifically, you will:
- Define the major components of Azure Storage
- Understand the different types of blobs and their intended use
- Learn basic programming APIs for table storage
- Discover how queues are used to pipeline cloud compute node together
- Learn to integrate Azure files with multiple applications
- Understand the tradeoffs between standard/premium storage and unmanaged/managed disks
OK, so let's take a closer look at what we can do with Azure File Shares. The first thing we're gonna do is we'll navigate to our Storage account and we'll create a New Share. That's easy enough. Click on Files, you can see we already have one in here, this is based on some previous demos we've done with a function app, so I wanna create a new one.
So, we will call this one travel pics and our quota can just be a gigabyte. I believe a terabyte is the largest size of File Share you can create, but this is all I need. There we go, alright. Alright, so we've created our Share, travel pics, of course there's nothing in it yet at this point. So you know, let's think a little bit about what we can do.
Ultimately it is a File Share, so the most, you know, kind of most obvious thing you can do would be to mount it in a Virtual Machine, so that we could navigate the File system, or the files in the Share that way. You can do this from Windows or from Linux, either one works well. The easiest thing to do would be, if you just click on this Connect button up here on the right hand side, you get some information on how to connect to it.
This is a bunch of, you know, it's a bunch of kind of narrow text here, I've copied this information already, so I'll, we'll switch over and I'll show you how to mount it from Windows. The one thing I will note is in the text, that I just showed you, just did mention that. You clearly didn't catch it, 'cause I didn't show it to you for long enough, but because we're relying on the SMB protocol, you need to open port 445 through your firewall on your local network to allow this to work, our File Share to work up to Azure.
So I'm going to, this is actually done for you automatically if you're running a VM in the Cloud in Azure. If I were running on my local, if I, we're going to connect directly from my local machine, then I would have to open up port 445. I'm going to, let me switch over to show you the VM, that I have running in the Cloud.
So this is a Virtual Machine, it's got, it's kind of like a basic developer box. It's, it is running in Azure in the same data center as the Share, that's not required, but just incidentally. So, if we look at the kind of the Explorer version, Explorer window here, you can see that I have a main disk C, I have a temporary storage disk D and I wanna mount this Share.
So there are a couple of different ways to do this. The easiest thing to do is to kind of use that text that I showed you when I clicked on the Connect button a moment ago. I've already copied it, I already have it in my PowerShell history, so I'll just kind of pull it back up and run this and you can see that it's succeeded.
If I go back to Explorer, you can see down here I now have the Share called travel pics. So OK, that's good. If I can click on it and I can open it up, of course there's nothing in there right now, so it's not super interesting at the moment, but we'll change that here momentarily. So, let me get out of this VM for a second and I'm gonna switch back to, on my local machine, I'm gonna switch back to Storage Explorer.
So we've seen this tool before. This allows you to browse queues, blogs, tables and also File Shares. So I'm going to navigate into the Storage account, where I've just created my Share, open up File Shares, you can see I have two in here, including one called travel pics, so I'll open that one up. I get the nice window, that shows me nothing, of course, because I have nothing in here yet.
So let's add a couple of items to this folder, so that we can kind of see something interesting happen. So I'm gonna drag a couple of files over here. We can see that these are a couple of images, they've been, if we look down at the bottom of the screen, we get kind of a status that says, yes, they've been added correctly to our Share.
So if I flip back to my VM, then sure enough, I can actually see three images. These are three images from a recent ski trip, that I took with my family to Utah, here in the western US. I'm gonna open up, again, this is on the Virtual Machine running in the Cloud, just to kind of keep things simple. I'm gonna create a new dot NET Console Application.
I'm gonna do this in dot NET, 'cause it's kind of quick and dirty and it's easy for me to do. The same thing applies, you know, there's nothing up my sleeve here, the same thing applies if you're, if this is a Node. js app or a Java app, any technology that talks to a local file system, whether it's on Windows or on Linux, you can leverage the fact that the operating system can forward request to the Share using SMB, so you know, these legacy applications may be that you have, that maybe rely again, on file system APIs can still work in the Cloud.
So let's just whip up a little bit of code here. We'll say foreach file in, let's see, we'll say Directory and we'll have to bring that name space in, so your system Data IO and we'll say GetFiles and the name of the Share, the drive letter, that we're using in particular for Windows is X, so that's the directory, that I'm going to point at here.
And again, if you don't know C Sharp, you don't know Dot NET, or even if you're not a programmer really, don't worry too much about the precise details of what's happening here, just think big picture. We're pointing out our File Share, you know, using its drive letter, it's kind of common name and we're just going to enumerate all of the files, and then just print out the name of the files, that are there.
So we'll say file which I believe is yes, that's just the name of the file itself. So that should work. Alright, so if I hit Control+F5, that will run this and we should see, once it builds, we should see the names of the files. Alright, so yes, it ran and you can see, let me zoom in a little bit, get the Magnifier out of the way and yeah, you can see the names of the images right there, which constitute the names of the files, that were put into that Share.
Close down that. Alright, so that hopefully motivates the point a little bit as far as the ability to support lift and shift scenarios for applications, that rely on file system APIs, instead of having to rewrite those in target, say blog storage or table storage, or some other Cloud-based storage, you have the option of using File Shares in Azure to hopefully make that migration process a bit simpler.
About the Author
Josh Lane is a Microsoft Azure MVP and Azure Trainer and Researcher at Cloud Academy. He’s spent almost twenty years architecting and building enterprise software for companies around the world, in industries as diverse as financial services, insurance, energy, education, and telecom. He loves the challenges that come with designing, building, and running software at scale. Away from the keyboard you'll find him crashing his mountain bike, drumming quasi-rythmically, spending time outdoors with his wife and daughters, or drinking good beer with good friends.