aws-samples / aws-samples/aws-systems-manager-amazon-ebs-management

Python script fails when the cloudtrail event count is high

Open
#4 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
12
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Suggest to add
EndTime=(startDateTime+timedelta(days=2)) attribute while searching the cloudtrail events on the below fn.
Without endtime the fn tries to check all the cloudtrail logs and fails with ratelimit error.
############################
def getCloudTrailEvents(startDateTime, rgn):
# gets CloudTrail events from startDateTime until "now"
cloudTrail = boto3.client('cloudtrail', region_name=rgn)
attrList = [{'AttributeKey': 'ResourceType', 'AttributeValue': 'AWS::EC2::Volume'}]
eventList = []
#Added attribute for end date.
response = cloudTrail.lookup_events(LookupAttributes=attrList, StartTime=startDateTime,EndTime=(startDateTime+timedelta(days=2)), MaxResults=50)
eventList += response['Events']
print(response)
while('NextToken' in response):
response = cloudTrail.lookup_events(LookupAttributes=attrList, StartTime=startDateTime,EndTime=(startDateTime+timedelta(days=2)), MaxResults=50, NextToken=response['NextToken'])
eventList += response['Events']
return eventList

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.