aws-athena查询语句总结

完全归于本人mysql语句小白,是一点也写不出来,故汇总到此

1. cloudtrail
bash 复制代码
## 查询事件排序
SELECT  eventname,eventtime,count(eventname) as num  FROM your_athena_tablename
where eventtime between '2024-11-10' and '2024-11-11' group by eventname,eventtime order by num desc


## 查询具体事件名对应的详细信息
SELECT  *  FROM your_athena_tablename where eventname = 'GetCallerIdentity' and  eventtime between '2024-11-10' and '2024-11-11' limit 50

## 确定 CloudTrail 事件数量导致的成本增长情况
SELECT eventName,count(eventName) AS NumberOfChanges,eventSource
FROM your_athena_tablename
WHERE eventtime >= '2024-11-10T00:00:00Z'and eventtime < '2024-11-11T00:00:00Z'
GROUP BY eventName, eventSource
ORDER BY NumberOfChanges DESC

## 显示特定访问密钥的所有记录的 AWS API 活动
SELECT eventTime, eventName, userIdentity.principalId
FROM your_athena_tablename
WHERE userIdentity.accessKeyId like 'access_key_id'

## 确定您的 EC2 实例的所有安全组更改
SELECT eventname, useridentity.username, sourceIPAddress, eventtime, requestparameters
FROM your_athena_tablename
WHERE (requestparameters like '%sg-5887f224%' or requestparameters like '%sg-e214609e%' or requestparameters like '%eni-6c5ca5a8%')
and eventtime > '2017-02-15T00:00:00Z'
order by eventtime asc;

## 显示过去 24 小时内的所有控制台登录信息
SELECT useridentity.username, sourceipaddress, eventtime, additionaleventdata
FROM your_athena_tablename
WHERE eventname = 'ConsoleLogin'
and eventtime >= '2017-02-17T00:00:00Z'
and eventtime < '2017-02-18T00:00:00Z';

## 显示过去 24 小时内所有失败的控制台登录尝试
SELECT useridentity.username, sourceipaddress, eventtime, additionaleventdata
FROM your_athena_tablename
WHERE eventname = 'ConsoleLogin'
and useridentity.username = 'HIDDEN_DUE_TO_SECURITY_REASONS'
and eventtime >= '2017-02-17T00:00:00Z'
and eventtime < '2017-02-18T00:00:00Z';

## 确定缺少的 IAM 权限
SELECT count (*) as TotalEvents, useridentity.arn, eventsource, eventname, errorCode, errorMessage
FROM your_athena_tablename
WHERE (errorcode like '%Denied%' or errorcode like '%Unauthorized%')
AND eventtime >= '2019-10-28T00:00:00Z'
AND eventtime < '2019-10-29T00:00:00Z'
GROUP by eventsource, eventname, errorCode, errorMessage, useridentity.arn
ORDER by eventsource, eventname

## 如果结果未显示失败的 API 调用,则通过类似于下面这样的方法扩大查询范围:
SELECT count (*) as TotalEvents, useridentity.arn, eventsource, eventname, errorCode, errorMessage
FROM your_athena_tablename
WHERE errorcode <> ''
AND eventtime >= '2019-10-28T00:00:00Z'
AND eventtime < '2019-10-29T00:00:00Z'
GROUP by eventsource, eventname, errorCode, errorMessage, useridentity.arn
ORDER by eventsource, eventname
相关推荐
AWS官方合作商6 小时前
AWS GPU实例深度解析:G系列与P系列如何选择?
云计算·aws
北辰浮光11 小时前
[Amplify]项目aws-amplfiy服务旧版本升级v6经验分享
云计算·aws
互联网老欣1 天前
2025年保姆级教程:阿里云服务器部署Dify+Ollama,打造专属AI应用平台
服务器·阿里云·ai·云计算·dify·ollama·deepseek
Altair12312 天前
nginx的https的搭建
运维·网络·nginx·云计算
AKAMAI2 天前
从客户端自适应码率流媒体迁移到服务端自适应码率流媒体
人工智能·云计算
G31135422732 天前
从零开始 通义千问大模型本地化到阿里云通义千问API调用
阿里云·云计算
Akamai中国3 天前
提升 EdgeWorker 可观测性:使用 DataStream 设置日志功能
人工智能·云计算·云服务
XINVRY-FPGA3 天前
XCVP1802-2MSILSVC4072 AMD Xilinx Versal Premium Adaptive SoC FPGA
人工智能·嵌入式硬件·fpga开发·数据挖掘·云计算·硬件工程·fpga
孤廖3 天前
终极薅羊毛指南:CLI工具免费调用MiniMax-M2/GLM-4.6/Kimi-K2-Thinking全流程
人工智能·经验分享·chatgpt·ai作画·云计算·无人机·文心一言
伞啊伞3 天前
DR模式部署
云计算