Get-SNSTopic确实存在,但它看起来像映射到列表主题API 并简单地返回 ARN 列表——您所描述的行为。API 和 CLI 似乎有类似的限制。
您可以通过包装Get-SNSTopicAttribute将 arn 拆分为多个部分,从而在功能上获得所需的内容:
Function Get-SNSTopicByName
{
param
(
[string]$Region = 'us-east-1',
[string]$AWSAccountNumber = '123456781234',
[string]$TopicName
)
$topicArn = "arn:aws:sns:$($Region):$($AWSAccountNumber):$($TopicName)"
Get-SNSTopicAttribute -TopicArn $topicArn
}
Get-SNSTopicByName -TopicName "my-topic"
Get-SNSTopicAttribute 返回Dictionary<string, string>
有关该主题的有用信息,如果该主题不存在,也会出错。这似乎更接近你什么。
您可以通过密钥访问获取各个部分:
PS C:/> $result = Get-SNSTopicByName -TopicName "my-topic"
PS C:/> $result["TopicArn"]
arn:aws:sns:us-east-1:123456781234:my-topic
PS C:/> $result["DisplayName"]
My Test Topic (Dev)