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
相关推荐
HaoHao_0101 天前
云消息队列 Kafka 版
分布式·阿里云·kafka·云计算·云服务器
sinat_307021531 天前
大数据技术与应用——大数据处理技术(一)(山东省大数据职称考试)
大数据·云计算
HaoHao_0102 天前
云消息队列 RabbitMQ 版
阿里云·云计算·云服务器
終不似少年遊*2 天前
云计算HCIP-OpenStack01
云原生·云计算·学习笔记·openstack·hcip·虚拟化
云计算DevOps-韩老师2 天前
【网络云计算】2024第51周-每日【2024/12/20】小测-理论-周测
云计算
jmoych2 天前
我在华为的安全日常
大数据·运维·网络·安全·华为·架构·云计算
HaoHao_0102 天前
应用实时监控服务ARMS
阿里云·云计算·云服务器
树莓集团2 天前
什么是数字化转型?对企业发展的帮助有哪些?
大数据·人工智能·云计算·新媒体运营·媒体
创实信息2 天前
GitHub企业版:AWS CodeCommit迁移的最佳路径与技术优势
git·ci/cd·github·aws·github企业版·aws codecommit
林农2 天前
C05S13-MySQL数据库备份与恢复
运维·mysql·云计算