Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
Created November 26, 2022 15:40
Show Gist options
  • Save manjeettahkur/25848ce92749cbbe865ffad4b13f3fa6 to your computer and use it in GitHub Desktop.
Save manjeettahkur/25848ce92749cbbe865ffad4b13f3fa6 to your computer and use it in GitHub Desktop.
1. Query to your local database to check that cloudtrail data is present in the local database.
IF yes
// It means you have stored some data from cloudtrail before.
// And now you are going to do request to cloudtrail for new trail events.
// Note - At a time of the first request you don't have a token (i.e. next-token)
GOTO Step 3
ELSE
// It means you have not stored any data from cloudtrail before.
// And now you are going to do the first request to cloudtrail.
// Note - At a time of the first request you don't have a token (i.e. next-token)
GOTO Step 2
2. LOOP true
token = nil
IF token
// Send request to cloudtrail to get next bactch of latest cloudtrail events, now pass token(i.e. next-token) as parameter.
// Which will return the maximum latest 50 trail events.
// It will also return next-token if more cloudtrail events are remaining.
IF next-token
token = next-token
ELSE
BREAK LOOP;
END
ELSE
// Send request to cloudtrail to get the latest cloudtrail events.
// Which will return the maximum latest 50 trail events.
// It will also return next-token if more cloudtrail events are remaining.
IF next-token
token = next-token
ELSE
BREAK LOOP;
END
END
END
3. LOOP true
token = nil
start_date_time = max_trail_event_date_time_form_local_db
IF token
// Send request to cloudtrail to get next bactch of latest cloudtrail events, now pass token and start_date_time(i.e. next-token and max_event_date_time_form_local_db) as parameters.
// Which will return the maximum latest 50 events which are logged after start_date_time.
// It will also return next-token if more cloudtrail events are remaining.
IF next-token
token = next-token
ELSE
BREAK LOOP;
END
ELSE
// Send request to cloudtrail to get the latest cloudtrail events, now pass start_date_time(i.e. max_trail_event_date_time_form_local_db) as parameter.
// Which will return the maximum latest 50 events which are logged after start_date_time.
// It will also return next-token if more cloudtrail events are remaining.
IF next-token
token = next-token
ELSE
BREAK LOOP;
END
END
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment