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
相关推荐
汤米粥37 分钟前
通过PHP创建AWS的CloudFront并绑定证书添加备用域名
服务器·云计算·aws
Z1eaf_complete2 小时前
Docker的基础使用
运维·docker·容器·云计算
汤米粥3 小时前
aws中AcmClient.describeCertificate返回值中没有ResourceRecord
aws
汤米粥3 小时前
怎么样绑定域名到AWS(亚马逊云)服务器
服务器·云计算·aws
小安运维日记6 小时前
CKA认证 | Day3 K8s管理应用生命周期(上)
运维·云原生·容器·kubernetes·云计算·k8s
眷怀21 小时前
网卡绑定bonding
linux·运维·服务器·网络·云计算
数勋API1 天前
银行卡归属地查询API接口如何用PHP调用
开发语言·云计算·php
zhojiew1 天前
aws xray通过设置采样规则对请求进行过滤
aws
tmgmforex20241 天前
亚马逊云计算部门挑战英伟达,提供免费AI计算能力
人工智能·科技·云计算