如何将boto3 cloudwatch用于SageMaker提交的培训工作?

时间:2018-12-05 20:43:57

标签: amazon-web-services boto3 amazon-cloudwatch amazon-sagemaker

我已经从AWS SageMaker提交了一些培训工作。我想使用boto3 cloudwatch api来获取要在jupyter笔记本中显示的cloudwatch数据,而不是使用CloudWatch UI。

1 个答案:

答案 0 :(得分:1)

您可以使用CloudWatch GetMetricWidgetImage API将图形添加到笔记本中。

这是一个例子:

import boto3
from PIL import Image
from io import BytesIO

widget = '''{
    "metrics": [
        [ "namespace", "metricname", "dim1", "value1", "dim2", "value2", "dim3", "value3", { "stat": "Average", "id": "m0r0" } ]
    ],
    "title": "Title of the graph",
    "view": "timeSeries",
    "stacked": false,
    "width": 600,
    "height": 400,
    "start": "-PT3H",
    "end": "P0D"
}'''

client = boto3.client('cloudwatch')

response = client.get_metric_widget_image(
    MetricWidget=widget
)

Image.open(BytesIO(response['MetricWidgetImage']))

您可以通过以下方法来获取小部件定义:在CloudWatch Console中打开所需的指标,单击Source标签,然后选择底部的Image API视图。根据自己的喜好调整宽度和高度。

您还需要调整SageMaker执行角色的策略,以允许调用GetMetricWidgetImage。