Prevent duplicate affected entities in non org mode #79
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Issue:
Currently when not using org mode AHA will report duplicate affected entities when an event has a high number of impacted entities. This is due to the
get_health_accounts
function returning a list with an account ID appended for each iteration of thedescribe_affected_entities
paginator, resulting in a list of the same single account ID repeated several times.The
get_affected_entities
function then takes this list of duplicate account IDs (since in non org mode there is only one account being polled) and adds the same affected entities for each item in the list.The Proposed Solution:
The updated code reworks the
get_affected_entities
function so that it better handles both org mode and non org mode by having the for loop over the impacted accounts run only for org mode and making theaffected_accounts
parameter optional so that it does not need to be passed when in non org mode.The
describe_events
function now does not need to callget_health_accounts
and only callsget_affected_entities
, which has the added benefit of removing a redundant call to describe the affected entities. It also deletes theget_health_accounts
function altogether as it is no longer needed anywhere in the lambda. Theaffected_accounts
variable is populated once the affected entities are pulled by pulling it from the first entity in theaffected_entities
list so that it can still be added to the DynamoDB item.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.