Bedrock 调用次数比预期多了一倍?CloudTrail 5 分钟定位元凶

复盘成本发现 Bedrock 调用量异常偏高。CloudTrail 一查------一个忘关的测试 Lambda 在持续调用。

CloudTrail 记录 AWS 账号里所有 API 调用。对 AI Agent 来说,它能告诉你:谁调了 Bedrock、调了哪个模型、什么时间、从哪个 IP。

开启 Bedrock 数据事件

默认 CloudTrail 不记录 InvokeModel(属于数据事件),需要手动开:

bash 复制代码
aws cloudtrail put-event-selectors \
  --trail-name your-trail \
  --advanced-event-selectors '[{
    "Name": "Bedrock events",
    "FieldSelectors": [
      {"Field": "eventCategory", "Equals": ["Data"]},
      {"Field": "resources.type", "Equals": ["AWS::Bedrock::Model"]}
    ]
  }]'

实用查询(CloudWatch Logs Insights)

按小时统计调用量:

java 复制代码
fields @timestamp, requestParameters.modelId
| filter eventSource = "bedrock.amazonaws.com" and eventName = "InvokeModel"
| stats count(*) by bin(1h)

按模型统计:

sql 复制代码
fields requestParameters.modelId
| filter eventSource = "bedrock.amazonaws.com"
| stats count(*) as cnt by requestParameters.modelId
| sort cnt desc

查半夜异常调用:

less 复制代码
filter eventSource = "bedrock.amazonaws.com"
| filter datepart(@timestamp, "hour") < 6 or datepart(@timestamp, "hour") > 22

设告警

bash 复制代码
# Metric Filter
aws logs put-metric-filter \
  --log-group-name /aws/cloudtrail/bedrock-audit \
  --filter-name BedrockInvokeCount \
  --filter-pattern '{ $.eventSource = "bedrock.amazonaws.com" && $.eventName = "InvokeModel" }' \
  --metric-transformations metricName=BedrockInvokeModelCount,metricNamespace=Custom/Bedrock,metricValue=1

# 每小时超 100 次报警
aws cloudwatch put-metric-alarm \
  --alarm-name bedrock-high-invoke \
  --metric-name BedrockInvokeModelCount \
  --namespace Custom/Bedrock \
  --statistic Sum --period 3600 --threshold 100 \
  --comparison-operator GreaterThanThreshold \
  --evaluation-periods 1 \
  --alarm-actions arn:aws:sns:us-west-2:123456789012:ops-alerts

日志成本

S3 存长期($0.023/GB/月),CloudWatch Logs 存 30 天方便查( �L �Ј9�a9ai{�"x� �L9i*yd#�/k�X�Y\�9� zd�x� ���-�HRHY�[�9�9o�yi!�."y.��ie��&�PSH9�y��fd8� U��[��[�9�y�dy��8� P��Y�Z[9�yk�z+�x� ���KKB���9g*9.��jk:"�.�y��y��9."�j�:+�z`&�/���

相关推荐
deepseek231 天前
硬预算帽默认值拆解:AWS 九月上线支出上限、GCP 七月跟进,Agent 时代按量付费必须默认断供
人工智能·llm·云计算·agent·aws
johnny2333 天前
AWS系列之Glue
aws
范桂飓4 天前
AWS Agent Infra 架构分析
java·架构·aws
johnny2335 天前
本地AWS云栈工具LocalStack:简介、原理、实战
aws
johnny2335 天前
AWS系列之官方CLI、AWS Local:简介、实战
aws
翼龙云_cloud21 天前
亚马逊云代理商:GPT-6 Astra 上线 Amazon Bedrock API 调用与企业集成实操
云计算·aws·gpt-6 astra
上海英方软件股份有限公司21 天前
什么是 VMware Cloud on AWS 灾难恢复
云计算·vmware·虚拟化·aws·容灾·灾难恢复·云灾备
yunlaodacom23 天前
AWS亚马逊云服务代理商:EC2和S3为什么建议放在同一Region?跨Region流量费和网络成本怎么规划
网络·云计算·aws
科技每日热闻23 天前
AWS Activate云积分可以用于哪些云服务和AI开发场景?
人工智能·ai·云计算·aws
2501_9304724424 天前
深度复盘|数据库迁移实战(上):腾讯云助手解析慢查询日志,定位索引缺失与语法不兼容
数据库·阿里云·ffmpeg·云计算·腾讯云·aws