小编Hel*_*ios的帖子

如何正确使用 CloudWatch boto3 API 从指标中检索数据?

我正在使用 Python3 的 boto3 尝试使用此处记录的 get_metric_statistics 函数从 SQS 的指标中提取数据:

https://boto3.readthedocs.io/en/latest/reference/services/cloudwatch.html#CloudWatch.Client.get_metric_statistics

这是我尝试拉取它的代码:

import boto3
import sys
from datetime import datetime, timedelta

client = boto3.client('cloudwatch')

response = client.get_metric_statistics(
    Namespace='SQS',
    MetricName='NumberOfEmptyReceives',
    Dimensions=[
        {
            'Name' : 'QueueName',
            'Value' : 'AlertNotifications'
        }
    ],  
    StartTime=datetime.utcnow() - timedelta(seconds=600),
    EndTime=datetime.utcnow(),
    Period=60,
    Statistics=[
        'Sum'
    ]
)

print(response)
sys.exit(0)
Run Code Online (Sandbox Code Playgroud)

我从 API 得到了响应,其中 HTTP 状态代码为 200,因此可以正常工作,但我没有得到任何数据点。我还仔细检查了我是否使用 boto3.setup_default_session() 调用了正确的配置文件。

我还仔细检查了我的数据是否存在:https ://i.stack.imgur.com/cRGQo.png

有人发现我做错了什么吗?

amazon-web-services python-3.x amazon-cloudwatch boto3 amazon-cloudwatch-metrics

2
推荐指数
1
解决办法
4414
查看次数