I am writing a query to get Amazon Athena records for the past one week only. Here is what I wrote so far:
WITH events AS (
SELECT
event.eventVersion,
event.eventID,
event.eventTime,
event.eventName,
event.eventType,
event.eventSource,
event.awsRegion,
event.sourceIPAddress,
event.userAgent,
event.userIdentity.type AS userType,
event.userIdentity.arn AS userArn,
event.userIdentity.principalId as userPrincipalId,
event.userIdentity.accountId as userAccountId,
event.userIdentity.userName as userName
FROM cloudtrail.events
CROSS JOIN UNNEST (Records) AS r (event)
)
SELECT userName,sourceIPAddress,eventName,eventTime FROM events WHERE eventName='ConsoleLogin';
But I am not sure how to write it to extract records for the past 1 week only.
eventTimeis of typedate? Then surely addingAND now() - eventTime < interval '1 week'to theWHEREclause would do it? – Colin 't Hart Apr 21 '17 at 14:13eventTimeis a varchar. Seriously bad design which you should fix. – Colin 't Hart Apr 24 '17 at 07:56