I am using the C# management API of Azure to create my resources in the cloud. I am stuck creating a container in the blob storage. I did create a storage account following these instructions:
// storageAccount here is a Microsoft.Azure.Management.Storage.Fluent.IStorageAccount instance
var storageAccount = _azure.StorageAccounts
.Define(name)
.WithRegion(region)
.WithExistingResourceGroup(resourceGroup)
.WithBlobEncryption()
.WithOnlyHttpsTraffic()
.WithBlobStorageAccountKind()
.WithAccessTier(AccessTier.Hot)
.Create();
But I do not know how to go on from there. From the Microsoft documentation it seems that I have to retrieve a Microsoft.WindowsAzure.Storage.CloudStorageAccount
instance, but the storageAccount
instance I obtain with the above code lives in the namespace Microsoft.Azure.Management.Storage.Fluent
, and I have not found any way to get the CloudStorageAccount
from there.
Is it possible to create containers directly with the API in the fluent namespace? If not, how do I get the CloudStorageAccount
instance from my IStorageAccount
one?
This answer in SO is not helpful because it does use the Microsoft.WindowsAzure
namespace directly.
Is it possible to create containers directly with the API in the fluent namespace? If not, how do I get the CloudStorageAccount instance from my IStorageAccount one?
At least as of today, it is not possible. When it comes to managing storage accounts in Azure, there are two REST APIs - Storage Resource Provider REST API
and Storage Service REST API
. Former deals with management of storage account themselves (like creation/updation etc.) while the latter deals with the data in storage account. You can say that the former API deals with control plane and the latter deals with data plan. Creation of a blob container falls under latter category.
Fluent API
you mentioned is a wrapper over Storage Resource Provider API
while Microsoft.WindowsAzure.Storage
library is a wrapper over Storage Service REST API
. You would need to reference this library in your project to create blob containers.
What you could do is get the access key (key 1 or key 2) using the Fluent API. Once you have the key, you will create an instance of CloudStorageAccount
using Microsoft.WindowsAzure.Storage library and create a blob container using that. I know that this is not the answer you're looking for but unfortunately this is the only way as of today.
This is now possible with Fluent API. Using your StorageAccount
, you can do:
storageAccount.Manager.BlobContainers.DefineContainer(containerName)
.WithExistingBlobService(resourceGroupName, storageAccountName)
.WithPublicAccess(PublicAccess.None)
.CreateAsync();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With