Skip to content

Commit efe72c9

Browse files
authored
aws - config-poll-rule mode post results with chunked evaluation (cloud-custodian#6461)
1 parent cea9811 commit efe72c9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

c7n/policy.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,19 @@ def _get_client(self):
763763
return utils.local_session(
764764
self.policy.session_factory).client('config')
765765

766+
def put_evaluations(self, client, token, evaluations):
767+
for eval_set in utils.chunks(evaluations, 100):
768+
self.policy.resource_manager.retry(
769+
client.put_evaluations,
770+
Evaluations=eval_set,
771+
ResultToken=token)
772+
766773
def run(self, event, lambda_context):
767774
cfg_event = json.loads(event['invokingEvent'])
768775
resource_type = self.policy.resource_manager.resource_type.cfn_type
769776
resource_id = self.policy.resource_manager.resource_type.id
770777
client = self._get_client()
778+
token = event.get('resultToken')
771779

772780
matched_resources = set()
773781
for r in PullMode.run(self):
@@ -786,11 +794,8 @@ def run(self, event, lambda_context):
786794
Annotation='The resource is not compliant with policy:%s.' % (
787795
self.policy.name))
788796
for r in matched_resources]
789-
if evaluations:
790-
self.policy.resource_manager.retry(
791-
client.put_evaluations,
792-
Evaluations=evaluations,
793-
ResultToken=event.get('resultToken', 'No token found.'))
797+
if evaluations and token:
798+
self.put_evaluations(client, token, evaluations)
794799

795800
evaluations = [dict(
796801
ComplianceResourceType=resource_type,
@@ -800,11 +805,8 @@ def run(self, event, lambda_context):
800805
Annotation='The resource is compliant with policy:%s.' % (
801806
self.policy.name))
802807
for r in unmatched_resources]
803-
if evaluations:
804-
self.policy.resource_manager.retry(
805-
client.put_evaluations,
806-
Evaluations=evaluations,
807-
ResultToken=event.get('resultToken', 'No token found.'))
808+
if evaluations and token:
809+
self.put_evaluations(client, token, evaluations)
808810
return list(matched_resources)
809811

810812

0 commit comments

Comments
 (0)