Share via


PowerShell을 사용하여 사용자 지정 항목에 대한 이벤트 구독

이 스크립트는 사용자 지정 항목에 대한 이벤트에 대한 Event Grid 구독을 만듭니다.

Azure를 구독하고 있지 않다면 시작하기 전에 Azure 체험 계정을 만듭니다.

미리 보기 샘플 스크립트에는 Event Grid 모듈이 필요합니다. 설치하려면 Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery를 실행합니다.

샘플 스크립트 - 안정적

참고 항목

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.

# Provide the name of the topic you are subscribing to
$myTopic = "<your-custom-topic-name>"

# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Provide a name for resource group to create. It will contain the custom event.
$myResourceGroup = "<resource-group-name>"

# Create resource group
New-AzResourceGroup -Name $myResourceGroup -Location westus2

# Create custom topic
New-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $myTopic -Location westus2 

# Subscribe to the custom event. Include the resource group that contains the custom topic.
New-AzEventGridSubscription `
  -EventSubscriptionName demoSubscription `
  -Endpoint $myEndpoint `
  -ResourceGroupName $myResourceGroup `
  -TopicName $myTopic

샘플 스크립트 - 미리 보기 모듈

Important

PowerShell에서 이 Azure 기능을 사용하려면 AzureRM 모듈이 설치되어 있어야 합니다. 이 모듈은 Windows PowerShell 5.1에만 사용할 수 있는 이전 모듈로, 새로운 기능은 더 이상 받지 않습니다. PowerShell의 동일한 버전에 대해 설치된 경우 AzAzureRM 모듈은 호환되지 않습니다. 두 버전이 모두 필요한 경우:

  1. PowerShell 5.1 세션에서 Az 모듈을 제거합니다.
  2. PowerShell 5.1 세션에서 AzureRM 모듈을 설치합니다.
  3. PowerShell Core 6.x 이상을 다운로드하고 설치합니다.
  4. PowerShell Core 세션에서 Az 모듈을 설치합니다.
# You must have the latest version of the Event Grid PowerShell module.
# To install:
# Install-Module -Name AzureRM.EventGrid -AllowPrerelease -Force -Repository PSGallery

# Provide the name of the topic you are subscribing to
$myTopic = "<your-custom-topic-name>"

# Provide an endpoint for handling the events. Must be formatted "https://your-endpoint-URL"
$myEndpoint = "<your-endpoint-URL>"

# Provide the name of the resource group to create. It will contain the custom topic.
$myResourceGroup = "<resource-group-name>"

# Create resource group
New-AzResourceGroup -Name $myResourceGroup -Location westus2

# Create custom topic and get its resource ID.
$topicID = (New-AzEventGridTopic -ResourceGroupName $myResourceGroup -Name $myTopic -Location westus2).Id 

# Subscribe to the custom event. Include the resource group that contains the custom topic.
New-AzEventGridSubscription `
  -ResourceId $topicID `
  -EventSubscriptionName demoSubscription `
  -Endpoint $myEndpoint 

스크립트 설명

이 스크립트는 다음 명령을 사용하여 이벤트 구독을 만듭니다. 표에 있는 각 명령은 명령에 해당하는 문서에 연결됩니다.

명령 주의
New-AzEventGridSubscription Event Grid 구독을 만듭니다.

다음 단계