CloudTrail Lake SQL 제약
CloudTrail Lake 쿼리는 SQL 문자열입니다. 이 단원에서는 쿼리를 생성하는 데 사용할 수 있는 SQL 언어에 대해 설명합니다.
SELECT
명령문만이 허용됩니다. 쿼리 문자열은 데이터를 변경하거나 변형할 수 있습니다. API는 다음 템플릿에 표시된 인수 트리에 대해 SELECT
명령문의 범위를 제한합니다. 간단한 집계, 조건, 조인 연산자가 허용됩니다. 이 단원에서 설명하지 않은 키워드, 연산자 또는 함수는 허용되지 않습니다. 이벤트 데이터 스토어 ARN의 ID 부분인 이벤트 데이터 스토어 ID는 테이블의 유효한 값입니다.
SELECT [ DISTINCT ] columns [ Aggregate ] [ FROM Tables
event_data_store_ID
] [ WHERE columns [ Conditions ] ] [ GROUP BY columns [ DISTINCT | Aggregate ] ] [ HAVING columns [ Aggregate | Conditions ] ] [ ORDER BY columns [ Aggregate | ASC | DESC | NULLS | FIRST | LAST ] [ LIMIT [ INT ] ]
주제
CloudTrail 이벤트 레코드 필드에 대해 지원되는 스키마
다음은 CloudTrail 이벤트 레코드 필드에 유효한 SQL 스키마입니다.
[ { "Name": "eventversion", "Type": "string" }, { "Name": "useridentity", "Type": "struct<type:string,principalid:string,arn:string,accountid:string,accesskeyid:string, username:string,sessioncontext:struct<attributes:struct<creationdate:timestamp, mfaauthenticated:string>,sessionissuer:struct<type:string,principalid:string,arn:string, accountid:string,username:string>,webidfederationdata:struct<federatedprovider:string, attributes:map<string,string>>,sourceidentity:string,ec2roledelivery:string, ec2issuedinvpc:string>,invokedby:string,identityprovider:string>" }, { "Name": "eventtime", "Type": "timestamp" }, { "Name": "eventsource", "Type": "string" }, { "Name": "eventname", "Type": "string" }, { "Name": "awsregion", "Type": "string" }, { "Name": "sourceipaddress", "Type": "string" }, { "Name": "useragent", "Type": "string" }, { "Name": "errorcode", "Type": "string" }, { "Name": "errormessage", "Type": "string" }, { "Name": "requestparameters", "Type": "map<string,string>" }, { "Name": "responseelements", "Type": "map<string,string>" }, { "Name": "additionaleventdata", "Type": "map<string,string>" }, { "Name": "requestid", "Type": "string" }, { "Name": "eventid", "Type": "string" }, { "Name": "readonly", "Type": "boolean" }, { "Name": "resources", "Type": "array<struct<accountid:string,type:string,arn:string,arnprefix:string>>" }, { "Name": "eventtype", "Type": "string" }, { "Name": "apiversion", "Type": "string" }, { "Name": "managementevent", "Type": "boolean" }, { "Name": "recipientaccountid", "Type": "string" }, { "Name": "sharedeventid", "Type": "string" }, { "Name": "annotation", "Type": "string" }, { "Name": "vpcendpointid", "Type": "string" }, { "Name": "serviceeventdetails", "Type": "map<string,string>" }, { "Name": "addendum", "Type": "map<string,string>" }, { "Name": "edgedevicedetails", "Type": "map<string,string>" }, { "Name": "insightdetails", "Type": "map<string,string>" }, { "Name": "eventcategory", "Type": "string" }, { "Name": "tlsdetails", "Type": "struct<tlsversion:string,ciphersuite:string,clientprovidedhostheader:string>" }, { "Name": "sessioncredentialfromconsole", "Type": "string" }, { "Name": "eventjson", "Type": "string" } { "Name": "eventjsonchecksum", "Type": "string" } ]
AWS Config 구성 항목 레코드 필드에 대해 지원되는 스키마
다음은 구성 항목 레코드 필드에 유효한 SQL 스키마입니다. 구성 항목의 경우 eventcategory
의 값은 ConfigurationItem
이고 eventtype
의 값은 AwsConfigurationItem
입니다.
[ { "Name": "eventversion", "Type": "string" }, { "Name": "eventcategory", "Type": "string" }, { "Name": "eventtype", "Type": "string" }, "Name": "eventid", "Type": "string" }, { "Name": "eventtime", "Type": "timestamp" }, { "Name": "awsregion", "Type": "string" }, { "Name": "recipientaccountid", "Type": "string" }, { "Name": "addendum", "Type": "map<string,string>" }, { "Name": "eventdata", "Type": "struct<configurationitemversion:string,configurationitemcapturetime: string,configurationitemstatus:string,configurationitemstateid:string,accountid:string, resourcetype:string,resourceid:string,resourcename:string,arn:string,awsregion:string, availabilityzone:string,resourcecreationtime:string,configuration:map<string,string>, supplementaryconfiguration:map<string,string>,relatedevents:string, relationships:struct<name:string,resourcetype:string,resourceid:string, resourcename:string>,tags:map<string,string>>" } ]
AWS Audit Manager 증거 레코드 필드에 대해 지원되는 스키마
다음은 Audit Manager 증거 레코드 필드에 유효한 SQL 스키마입니다. Audit Manager 증거 레코드 필드의 경우 eventcategory
의 값은 Evidence
이고 eventtype
의 값은 AwsAuditManagerEvidence
입니다. Audit Manager를 사용하는 CloudTrail Lake에서 증거 집계에 대한 자세한 내용은 AWS Audit Manager 사용 설명서의 증거 찾기를 참조하세요.
[ { "Name": "eventversion", "Type": "string" }, { "Name": "eventcategory", "Type": "string" }, { "Name": "eventtype", "Type": "string" }, "Name": "eventid", "Type": "string" }, { "Name": "eventtime", "Type": "timestamp" }, { "Name": "awsregion", "Type": "string" }, { "Name": "recipientaccountid", "Type": "string" }, { "Name": "addendum", "Type": "map<string,string>" }, { "Name": "eventdata", "Type": "struct<attributes:map<string,string>,awsaccountid:string,awsorganization:string, compliancecheck:string,datasource:string,eventname:string,eventsource:string, evidenceawsaccountid:string,evidencebytype:string,iamid:string,evidenceid:string, time:timestamp,assessmentid:string,controlsetid:string,controlid:string, controlname:string,controldomainname:string,frameworkname:string,frameworkid:string, service:string,servicecategory:string,resourcearn:string,resourcetype:string, evidencefolderid:string,description:string,manualevidences3resourcepath:string, evidencefoldername:string,resourcecompliancecheck:string>" } ]
집계 함수, 조건 및 조인 연산자
다음은 허용되는 Aggregate
함수입니다.
SUM MIN MAX AVG COUNT
다음은 허용되는 Condition
연산입니다.
AND OR IN NOT IS (NOT) NULL LIKE < > <= >= <> != ( conditions ) #parenthesised conditions
다음은 허용되는 JOIN
연산입니다. 다중 테이블 쿼리 실행에 대한 자세한 내용은 고급 다중 테이블 쿼리 지원을 참조하세요.
UNION UNION ALL EXCEPT INTERSECT LEFT JOIN RIGHT JOIN INNER JOIN
지원되는 함수
다음은 CloudTrail Lake 쿼리에 지원되는 함수입니다. 설명 및 예제는 Presto 0.266 설명서 웹 사이트의 JSON 함수와 연산자
함수 |
---|
element_at(맵 | 배열, 객체 | 수) ➝ 객체 |
cardinality(맵 | 배열) ➝ BigInt |
날짜 변환 함수(다음 표 참조) |
map_values(맵) ➝ 배열(객체) |
map_keys(맵) ➝ 배열(객체) |
contains(배열, 객체) ➝ 부울 |
array_distinct(배열) ➝ 배열 |
array_max(배열) ➝ 객체, array_min(배열) ➝ 객체 |
slice(배열, 시작, 길이) ➝ 배열 |
json_parse(문자열) ➝ json |
is_json_scalar(json) ➝ 부울 |
json_extract(json, 문자열) ➝ Json |
json_extract_scalar(json, 문자열) ➝ 문자열 |
json_format(json) ➝ 문자열 |
json_array_contains(json_array, 객체) ➝ 부울 |
json_array_get(json_array, 인덱스) ➝ json |
json_array_length(json_array)➝ bigInt |
지원되는 날짜 변환 함수
지원되는 날짜 및 시간 함수에 대한 자세한 내용은 Presto 0.266 설명서 웹사이트의 날짜 및 시간 함수와 연산자
날짜 변환 함수 |
---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
고급 다중 테이블 쿼리 지원
CloudTrail Lake는 여러 이벤트 데이터 스토어에서 고급 쿼리 언어를 지원합니다. 하위 쿼리를 포함하지 않는 쿼리만 지원됩니다.
쿼리를 실행하려면 AWS CLI에서 start-query 명령을 사용합니다. 다음은 이 섹션의 샘플 쿼리 중 하나를 사용하는 예제입니다.
aws cloudtrail start-query --query-statement "Select eventId, eventName from EXAMPLEf852-4e8f-8bd1-bcf6cEXAMPLE UNION Select eventId, eventName from EXAMPLEg741-6y1x-9p3v-bnh6iEXAMPLE UNION ALL Select eventId, eventName from EXAMPLEb529-4e8f9l3d-6m2z-lkp5sEXAMPLE ORDER BY eventId LIMIT 10;"
응답은 QueryId
문자열이 됩니다. 쿼리 상태를 가져오려면 start-query
에 의해 반환된 QueryId
값을 사용하여 describe-query
를 실행합니다. 쿼리가 성공하면 get-query-results
을(를) 실행하여 결과를 가져옵니다.
UNION|UNION
ALL|EXCEPT|INTERSECT
이 릴리스에서는 다중 테이블 쿼리 또는 여러 이벤트 데이터 스토어에서 실행할 수 있는 쿼리를 추가합니다. 다음은 UNION
및 UNION ALL
을 사용하여 세 개의 이벤트 데이터 스토어 EDS1, EDS2, EDS3에서 이벤트 ID 및 이벤트 이름으로 이벤트를 찾는 예제 쿼리입니다. 먼저 각 이벤트 데이터 스토어에서 결과를 선택한 다음 결과를 연결하고 이벤트 ID별로 정렬한 다음 10개의 이벤트로 제한합니다.
Select eventId, eventName from EDS1 UNION Select eventId, eventName from EDS2 UNION ALL Select eventId, eventName from EDS3 ORDER BY eventId LIMIT 10;
LEFT|RIGHT|INNER
JOIN
이 릴리스에서는 다중 테이블 쿼리 또는 여러 이벤트 데이터 스토어에서 실행할 수 있는 쿼리를 추가합니다. 다음은 LEFT JOIN
을 사용하여 edsB
에 매핑된 eds2
라는 이벤트 데이터 스토어에서 기본(왼쪽) 이벤트 데이터 스토어인 edsA
의 이벤트와 일치하는 모든 이벤트를 찾는 예제 쿼리입니다. 반환된 이벤트는 2020년 1월 1일 또는 그 이전에 발생하며 이벤트 이름만 반환됩니다.
SELECT edsA.eventName, edsB.eventName, element_at(edsA.map, 'test') FROM eds1 as edsA LEFT JOIN eds2 as edsB ON edsA.eventId = edsB.eventId WHERE edsA.eventtime <= '2020-01-01' ORDER BY edsB.eventName;