aws-samples / aws-samples/aws-systems-manager-amazon-ebs-management
Python script fails when the cloudtrail event count is high
- 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
Assessment
This issue has not been assessed yet.