Skip to content

Instantly share code, notes, and snippets.

@coingraham
Created August 31, 2017 20:01
Show Gist options
  • Select an option

  • Save coingraham/7ed296b69e1104b5d2b1a3f07aecfe83 to your computer and use it in GitHub Desktop.

Select an option

Save coingraham/7ed296b69e1104b5d2b1a3f07aecfe83 to your computer and use it in GitHub Desktop.
Athena SQL
SELECT
eventtime,
CASE
when useridentity.type = 'IAMUser' then useridentity.username
when useridentity.type = 'Root' then useridentity.invokedby
when useridentity.type = 'AssumedRole' then useridentity.arn
ELSE
'undefined'
END as "userid",
sourceipaddress,
eventname,
json_extract_scalar( requestparameters, '$.name' ) as "hostname",
json_extract_scalar( requestparameters, '$.instances.slaveInstanceType' ) as "slave",
json_extract_scalar( requestparameters, '$.instances.instanceGroups' ) as "instancegroups",
json_extract_scalar( requestparameters, '$.instances.instanceGroups[0].instanceType' ) as "instancegrouptype0",
json_extract_scalar( requestparameters, '$.instances.instanceGroups[1].instanceType' ) as "instancegrouptype1",
json_extract_scalar( requestparameters, '$.instances.instanceGroups[2].instanceType' ) as "instancegrouptype2",
errorcode,
errormessage
FROM cloudtrail_logs_2017
WHERE eventsource = 'elasticmapreduce.amazonaws.com'
AND eventname in ('RunJobFlow')
AND useridentity.username = 'pipeline-controller'
ORDER BY eventtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment