1 回答

TA貢獻1853條經驗 獲得超9個贊
詳細步驟請參考這篇文章。
注意:
1.對于account name
,不要使用后綴.azuredatalakestore.net
2.對于身份驗證,我使用服務到服務身份驗證。它將使用 TENANT_id(AAD 中的目錄 id)、CLIENTID(AAD 中的應用程序 id)和 secret_key,您可以按照本文獲取它們。
3.安裝官方文檔中提到的以下版本包(你可以使用其他版本,但需要做一些小改動):
Microsoft.Azure.Management.DataLake.Store - This tutorial uses v2.1.3-preview.
Microsoft.Rest.ClientRuntime.Azure.Authentication - This tutorial uses v2.2.12.
示例代碼:
class Program
{
private static DataLakeStoreAccountManagementClient _adlsClient;
private static string _adlsAccountName;
private static string _resourceGroupName;
private static string _location;
private static string _subId;
static void Main(string[] args)
{
_adlsAccountName = "test333";
_resourceGroupName = "ivanrg";
_location = "East US 2";
_subId = "xxxx";
string TENANT = "xxxx";
string CLIENTID = "xxxx";
System.Uri ARM_TOKEN_AUDIENCE = new System.Uri(@"https://management.core.windows.net/");
System.Uri ADL_TOKEN_AUDIENCE = new System.Uri(@"https://datalake.azure.net/");
string secret_key = "xxxx";
var armCreds = GetCreds_SPI_SecretKey(TENANT, ARM_TOKEN_AUDIENCE, CLIENTID, secret_key);
// Create client objects and set the subscription ID
_adlsClient = new DataLakeStoreAccountManagementClient(armCreds) { SubscriptionId = _subId };
// Create Data Lake Storage Gen1 account
var adlsParameters = new DataLakeStoreAccount(location: _location);
_adlsClient.Account.Create(_resourceGroupName, _adlsAccountName, adlsParameters);
Console.WriteLine("--completed--");
Console.ReadLine();
}
private static ServiceClientCredentials GetCreds_SPI_SecretKey(string tenant, Uri tokenAudience, string clientId, string secretKey)
{
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
var serviceSettings = ActiveDirectoryServiceSettings.Azure;
serviceSettings.TokenAudience = tokenAudience;
var creds = ApplicationTokenProvider.LoginSilentAsync(
tenant,
clientId,
secretKey,
serviceSettings).GetAwaiter().GetResult();
return creds;
}
}
在 azure 門戶中檢查新創建的帳戶:
- 1 回答
- 0 關注
- 116 瀏覽
添加回答
舉報