AWS SNS支持公共度量信息,但不支持订阅特定的度量信息。但是,您可以使用AWS CloudWatch将SNS度量信息查询到指定命名空间和指标下。以下是查询SNS发送操作计数的代码示例:
import boto3
client = boto3.client('cloudwatch')
response = client.get_metric_statistics(
Namespace='AWS/SNS',
MetricName='NumberOfMessagesPublished',
Dimensions=[
{
'Name': 'TopicName',
'Value': 'YOUR_TOPIC_NAME'
},
],
StartTime='2021-09-01T00:00:00Z',
EndTime='2021-09-30T23:59:59Z',
Period=86400,
Statistics=['Sum']
)
print(response)
这将返回一个包含SNS发送操作计数的响应。您可以根据需要更改查询的度量信息。