Blob 스토리지 엔드포인트는 스토리지 계정 내의 모든 개체에 대한 기본 주소를 형성합니다. 스토리지 계정을 만들 때 사용할 엔드포인트 유형을 지정합니다. Blob 스토리지는 다음과 같은 두 가지 유형의 엔드포인트를 지원합니다.
- 표준 엔드포인트에는 고정 도메인 이름과 함께 고유한 스토리지 계정 이름이 포함됩니다. 표준 엔드포인트 형식은
https://<storage-account>.blob.core.windows.net
입니다.
- Azure DNS 영역 엔드포인트(미리 보기)는 Azure DNS 영역을 동적으로 선택하고 만들 때 스토리지 계정에 할당합니다. Azure DNS 영역 엔드포인트의 형식은
https://<storage-account>.z[00-99].blob.storage.azure.net
입니다.
애플리케이션이 Blob 스토리지 데이터 리소스에 연결하는 서비스 클라이언트 개체를 만들 때 엔드포인트를 참조하는 URI를 서비스 클라이언트 생성자에게 전달합니다. URI 문자열을 수동으로 생성하거나 Azure Storage 관리 라이브러리를 사용하여 런타임 시 서비스 엔드포인트를 쿼리할 수 있습니다.
Important
클라이언트 애플리케이션에서 서비스 엔드포인트를 참조하는 경우 캐시된 IP 주소에 대한 종속성을 사용하지 않는 것이 좋습니다. 스토리지 계정 IP 주소는 변경될 수 있으며 캐시된 IP 주소를 사용하면 예기치 않은 동작이 발생할 수 있습니다.
스토리지 계정 엔드포인트와 연결된 CNAME은 예고 없이 변경할 수 있습니다. 애플리케이션은 CNAME 레코드의 수 또는 해당 CNAME 레코드와 연결된 하위 도메인의 수에 종속되지 않아야 합니다.
또한 DNS 레코드의 TTL(Time to Live)을 적용하고 재정의하지 않는 것이 좋습니다. DNS TTL을 재정의하면 예기치 않은 동작이 발생할 수 있습니다.
자세한 내용은 CNAME 레코드, 하위 도메인 및 IP 주소를 참조하세요.
Azure Storage 관리 라이브러리는 Azure Storage 리소스 공급자에 대한 액세스를 프로그래밍 방식으로 제공합니다. 리소스 공급자는 Azure Resource Manager의 Azure Storage 구현입니다. 개발자는 관리 라이브러리를 사용하여 스토리지 계정 및 계정 구성을 관리하고 수명 주기 관리 정책, 개체 복제 정책, 불변성 정책을 구성할 수 있습니다.
이 문서에서는 Azure Storage 관리 라이브러리를 사용하여 Blob 스토리지 엔드포인트를 쿼리하는 방법을 알아봅니다. 그런 다음, 해당 엔드포인트를 사용하여 Blob 스토리지 데이터 리소스와 연결할 BlobServiceClient
개체를 만듭니다.
프로젝트 설정
이 문서의 코드 예제를 사용하려면 다음 단계에 따라 프로젝트를 설정합니다.
패키지 설치
패키지를 설치하여 이 예제에 사용된 라이브러리를 사용합니다.
dotnet add package
를 사용하여 다음 패키지를 설치합니다.
dotnet add package Azure.Identity
dotnet add package Azure.ResourceManager.Storage
dotnet add package Azure.Storage.Blobs
텍스트 편집기에서 pom.xml
파일을 엽니다.
azure-sdk-bom을 추가하여 최신 버전의 라이브러리에 대한 종속성을 가져옵니다. 다음 코드 조각에서 {bom_version_to_target}
자리 표시자를 버전 번호로 바꿉니다. azure-sdk-bom을 사용하면 각 개별 종속성의 버전을 지정하지 않아도 됩니다. BOM에 대해 자세히 알아보려면 Azure SDK BOM 추가 정보를 참조하세요.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>{bom_version_to_target}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
그런 다음, 종속성 그룹에 다음 종속성 요소를 추가합니다. Azure 서비스에 대한 암호 없는 연결에는 azure-identity 종속성이 필요합니다.
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-storage</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-management</artifactId>
<version>1.10.2</version>
</dependency>
npm install
를 사용하여 다음 패키지를 설치합니다.
npm install @azure/identity
npm install @azure/storage-blob
npm install @azure/arm-resources
npm install @azure/arm-storage
pip install
를 사용하여 다음 패키지를 설치합니다.
pip install azure-identity
pip install azure-storage-blob
pip install azure-mgmt-resource
pip install azure-mgmt-storage
앱 코드 설정
필요한 using
또는 import
지시문을 코드에 추가합니다. 코드 예제는 파일 간의 기능을 분할할 수 있지만 이 섹션에서는 모든 지시문이 함께 나열됩니다.
다음 using
지시문을 추가합니다.
using Azure.Core;
using Azure.Identity;
using Azure.Storage.Blobs;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Storage;
클라이언트 라이브러리 정보:
다음 import
지시문을 추가합니다.
import com.azure.identity.*;
import com.azure.storage.blob.*;
import com.azure.resourcemanager.*;
import com.azure.resourcemanager.storage.models.*;
import com.azure.core.management.*;
import com.azure.core.management.profile.*;
클라이언트 라이브러리 정보:
다음 require
문을 추가하여 모듈을 로드합니다.
const { DefaultAzureCredential } = require("@azure/identity");
const { BlobServiceClient } = require("@azure/storage-blob");
const { ResourceManagementClient } = require("@azure/arm-resources");
const { StorageManagementClient } = require("@azure/arm-storage");
클라이언트 라이브러리 정보:
다음 import
문을 추가합니다.
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.storage import StorageManagementClient
클라이언트 라이브러리 정보:
구독에 스토리지 리소스 공급자 등록
리소스 공급자를 사용하려면 먼저 Azure 구독에 등록해야 합니다. 이 단계는 구독당 한 번만 수행해야 하며 리소스 공급자 Microsoft.Storage가 현재 구독에 등록되어 있지 않은 경우에만 적용됩니다.
스토리지 리소스 공급자를 등록하거나 Azure portal, Azure CLI 또는 Azure PowerShell을 사용하여 등록 상태를 확인할 수 있습니다.
다음 예제와 같이 Azure 관리 라이브러리를 사용하여 등록 상태를 확인하고 스토리지 리소스 공급자를 등록할 수도 있습니다.
public static async Task RegisterSRPInSubscription(SubscriptionResource subscription)
{
ResourceProviderResource resourceProvider =
await subscription.GetResourceProviderAsync("Microsoft.Storage");
// Check the registration state of the resource provider and register, if needed
if (resourceProvider.Data.RegistrationState == "NotRegistered")
resourceProvider.Register();
}
public void RegisterSRPInSubscription(AzureResourceManager armClient) {
// Check the registration state of the resource provider and register, if needed
if (armClient.providers().getByName("Microsoft.Storage").registrationState() == "NotRegistered")
armClient.providers().register("Microsoft.Storage");
}
async function registerSRPInSubscription(resourceMgmtClient /*: ResourceManagementClient*/) {
// Check the registration state of the resource provider and register, if needed
if (resourceMgmtClient.providers.get("Microsoft.Storage").registrationState == "NotRegistered")
resourceMgmtClient.providers.register("Microsoft.Storage");
}
def register_srp_in_subscription(self, resource_mgmt_client: ResourceManagementClient):
if (resource_mgmt_client.providers.get("Microsoft.Storage").registration_state == "NotRegistered"):
resource_mgmt_client.providers.register("Microsoft.Storage")
참고 항목
등록 작업을 수행하려면 다음 Azure RBAC 작업에 대한 권한이 필요합니다. Microsoft.Storage/register/action 해당 권한은 기여자 및 소유자 역할에 포함되어 있습니다.
Blob 스토리지 엔드포인트 쿼리
지정된 스토리지 계정의 Blob 스토리지 엔드포인트를 검색하려면 속성 가져오기 작업을 호출하여 스토리지 계정 속성을 가져와야 합니다. 다음 코드 샘플에서는 데이터 액세스 및 관리 라이브러리를 모두 사용하여 지정된 스토리지 계정의 Blob 스토리지 엔드포인트를 가져옵니다.
지정된 스토리지 계정에 대한 속성을 얻으려면 StorageAccountCollection 개체에서 다음 메서드를 사용합니다.
이 메서드는 스토리지 계정을 나타내는 StorageAccountResource 개체를 반환합니다.
public static async Task<Uri> GetBlobServiceEndpoint(
string storageAccountName,
TokenCredential credential)
{
// TODO: replace with your subscription ID and resource group name
// You can locate your subscription ID on the Subscriptions blade
// of the Azure portal (https://portal.azure.com)
const string subscriptionId = "<subscription-id>";
const string rgName = "<resource-group-name>";
ArmClient armClient = new(credential);
// Create a resource identifier, then get the subscription resource
ResourceIdentifier resourceIdentifier = new($"/subscriptions/{subscriptionId}");
SubscriptionResource subscription = armClient.GetSubscriptionResource(resourceIdentifier);
// Get a resource group
ResourceGroupResource resourceGroup = await subscription.GetResourceGroupAsync(rgName);
// Get a collection of storage account resources
StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts();
// Get the properties for the specified storage account
StorageAccountResource storageAccount = await accountCollection.GetAsync(storageAccountName);
// Return the primary endpoint for the blob service
return storageAccount.Data.PrimaryEndpoints.BlobUri;
}
지정된 스토리지 계정에 대한 속성을 얻으려면 AzureResourceManager 개체에서 다음 메서드를 사용합니다.
이 메서드는 스토리지 계정의 변경이 불가능한 클라이언트 쪽 표현인 StorageAccount 인터페이스를 반환합니다.
public String GetBlobServiceEndpoint(String saName, DefaultAzureCredential credential) {
String subscriptionID = "<subscription-id>";
String rgName = "<resource-group-name>";
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
AzureResourceManager azureResourceManager = AzureResourceManager
.configure()
.authenticate(credential, profile)
.withSubscription(subscriptionID);
StorageAccount storageAccount = azureResourceManager.storageAccounts()
.getByResourceGroup(rgName, saName);
String endpoint = storageAccount.endPoints().primary().blob();
return endpoint;
}
지정된 스토리지 계정에 대한 속성을 얻으려면 StorageManagementClient 개체에서 다음 메서드를 사용합니다.
이 메서드는 스토리지 계정을 나타내는 Promise<StorageAccountsGetPropertiesResponse>
를 반환합니다.
async function getBlobServiceEndpoint(saName, credential) {
const subscriptionId = "<subscription-id>";
const rgName = "<resource-group-name>";
const storageMgmtClient = new StorageManagementClient(
credential,
subscriptionId
);
// Get the properties for the specified storage account
const storageAccount = await storageMgmtClient.storageAccounts.getProperties(
rgName,
saName
);
// Get the primary endpoint for the blob service
const endpoint = storageAccount.primaryEndpoints.blob;
return endpoint;
}
지정된 스토리지 계정에 대한 속성을 얻으려면 StorageManagementClient 개체에서 다음 메서드를 사용합니다.
이 메서드는 스토리지 계정을 나타내는 StorageAccount
개체를 반환합니다.
def get_blob_service_endpoint(self, storage_account_name, credential: DefaultAzureCredential) -> str:
subscription_id = "<subscription-id>"
rg_name = "<resource-group-name>"
storage_mgmt_client = StorageManagementClient(
credential=credential,
subscription_id=subscription_id
)
# Get the properties for the specified storage account
storage_account = storage_mgmt_client.storage_accounts.get_properties(
resource_group_name=rg_name,
account_name=storage_account_name
)
# Get blob service endpoint
endpoint = storage_account.primary_endpoints.blob
return endpoint
엔드포인트를 사용하여 클라이언트 개체 만들기
스토리지 계정에 대한 Blob 스토리지 엔드포인트가 있으면 클라이언트 개체를 인스턴스화하여 데이터 리소스로 작업할 수 있습니다. 다음 코드 샘플에서는 이전 예제에서 검색한 엔드포인트를 사용하여 BlobServiceClient
개체를 만듭니다.
// Create an instance of DefaultAzureCredential for authorization
TokenCredential credential = new DefaultAzureCredential();
// TODO: replace with your storage account name
string storageAccountName = "<storage-account-name>";
// Call out to our function that retrieves the blob service endpoint for the given storage account
Uri blobURI = await AccountProperties.GetBlobServiceEndpoint(storageAccountName, credential);
Console.WriteLine($"URI: {blobURI}");
// Now that we know the endpoint, create the client object
BlobServiceClient blobServiceClient = new(blobURI, credential);
// Do something with the storage account or its resources ...
String saName = "<storage-account-name>";
DefaultAzureCredential credential = new DefaultAzureCredentialBuilder().build();
AccountProperties accountProps = new AccountProperties();
String blobEndpoint = accountProps.GetBlobServiceEndpoint(saName, credential);
System.out.printf("URI: %s", blobEndpoint);
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
.endpoint(blobEndpoint)
.credential(credential)
.buildClient();
// Do something with the storage account or its resources ...
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential.
// See https://aka.ms/azsdk/js/identity/examples for more details.
const saName = "<storage-account-name>";
const credential = new DefaultAzureCredential();
// Call out to our function that retrieves the blob service endpoint for a storage account
const endpoint = await getBlobServiceEndpoint(saName, credential)
console.log(endpoint);
// Now that we know the endpoint, create the client object
const blobServiceClient = new BlobServiceClient(
endpoint,
credential);
// Do something with the storage account or its resources ...
storage_account_name = "<storage-account-name>"
credential = DefaultAzureCredential()
sample = BlobEndpointSample()
# Call out to our function that retrieves the blob service endpoint for a storage account
endpoint = sample.get_blob_service_endpoint(storage_account_name, credential)
print(f"URL: {endpoint}")
# Now that we know the endpoint, create the client object
blob_service_client = BlobServiceClient(account_url=endpoint, credential=credential)
# Do something with the storage account or its resources ...
다음 단계
전체 코드 샘플 보기(GitHub):
클라이언트 개체를 만드는 방법에 대한 자세한 내용은 데이터 리소스와 상호 작용하는 클라이언트 개체 만들기 및 관리를 참조하세요.