python-3.x - AWS lambda powertools Metrics 仅记录循环中的最后一个指标
问题描述
我正在使用AWS Lambda Powertools Python,并且需要将多个数据点放在我的函数中的一个指标中。
使用Metrics Utility,我的代码如下所示
from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit
metrics = Metrics()
@metrics.log_metrics
def lambda_handler(event, context):
# There are many things
for thing in event["things"]:
metrics.add_metric(
name="MyMetric",
unit=MetricUnit.Count,
value=thing['value']
)
使用此代码,只有最后一个 thing
被放入 cloudwatch 指标。
如何确保所有数据都things
发送到 cloudwatch 指标?
解决方案
推荐阅读
- javascript - 如果我需要 JS 中第一个循环的结果,如何避免运行两个循环
- python - Python 包位于 venv/lib/site-packages 文件夹中,显示为安装在 PyCharm 中,但抛出 ModuleNotFoundError
- swift - SwiftUI MacOs 选项卡
- mysql - Mysql:有没有更高效的嵌套聚合更新方式?
- node.js - express-graphql 中的 serverless vs serverfull?
- python-3.x - 如何从通过 REST API 执行的 Saltstack `cmd.run` 捕获返回码
- php - Laravel - phpunit 更新方法失败,我不知道为什么
- if-statement - google sheet - 使用 ARRAYFORMULA 对以上所有行求和
- python - 无法在 macOS“Big Sur”上通过 pip 或 conda 安装镶木地板
- python - 循环遍历多个 CSV 文件并与特定列合并 [Pandas]