Skip to content

Commit 4ef0a4a

Browse files
Cleanup
1 parent f2a8391 commit 4ef0a4a

File tree

4 files changed

+16
-16
lines changed
  • src/lambda
    • gc01_check_alerts_flag_misuse
    • gc02_check_account_mgmt_plan
    • gc02_check_iam_password_policy
    • gc12_check_marketplace

4 files changed

+16
-16
lines changed

src/lambda/gc01_check_alerts_flag_misuse/app.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def lambda_handler(event, context):
115115
logger.info("Received Event: %s", json.dumps(event, indent=2))
116116

117117
invoking_event = json.loads(event["invokingEvent"])
118+
if not is_scheduled_notification(invoking_event["messageType"]):
119+
logger.error("Skipping assessments as this is not a scheduled invocation")
120+
return
121+
118122
rule_parameters = json.loads(event.get("ruleParameters", "{}"))
119123
valid_rule_parameters = check_required_parameters(rule_parameters, [])
120124
execution_role_name = valid_rule_parameters.get("ExecutionRoleName", "AWSA-GCLambdaExecutionRole")
@@ -123,10 +127,6 @@ def lambda_handler(event, context):
123127
is_not_audit_account = aws_account_id != audit_account_id
124128
evaluations = []
125129

126-
if not is_scheduled_notification(invoking_event["messageType"]):
127-
logger.error("Skipping assessments as this is not a scheduled invocation")
128-
return
129-
130130
aws_config_client = get_client("config", aws_account_id, execution_role_name, is_not_audit_account)
131131
aws_s3_client = get_client("s3")
132132
aws_guard_duty_client = get_client("guardduty", aws_account_id, execution_role_name, is_not_audit_account)

src/lambda/gc02_check_account_mgmt_plan/app.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def lambda_handler(event, context):
2828
logger.info("Received Event: %s", json.dumps(event, indent=2))
2929

3030
invoking_event = json.loads(event["invokingEvent"])
31+
if not is_scheduled_notification(invoking_event["messageType"]):
32+
logger.error("Skipping assessments as this is not a scheduled invocation")
33+
return
34+
3135
rule_parameters = json.loads(event.get("ruleParameters", "{}"))
3236
valid_rule_parameters = check_required_parameters(rule_parameters, ["s3ObjectPath"])
3337
execution_role_name = valid_rule_parameters.get("ExecutionRoleName", "AWSA-GCLambdaExecutionRole")
@@ -40,10 +44,6 @@ def lambda_handler(event, context):
4044
compliance_type = "NOT_APPLICABLE"
4145
annotation = "Guardrail only applicable in the Audit Account"
4246

43-
if not is_scheduled_notification(invoking_event["messageType"]):
44-
logger.error("Skipping assessments as this is not a scheduled invocation")
45-
return
46-
4747
if is_not_audit_account:
4848
logger.info(
4949
"Account management plan document not checked in account %s - not the Audit account", aws_account_id

src/lambda/gc02_check_iam_password_policy/app.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def lambda_handler(event, context):
144144
"""
145145
logger.info("Received Event: %s", json.dumps(event, indent=2))
146146

147+
invoking_event = json.loads(event["invokingEvent"])
148+
if not is_scheduled_notification(invoking_event["messageType"]):
149+
return
150+
147151
password_assessment_policy = {
148152
"MinimumPasswordLength": 12,
149153
"RequireSymbols": True,
@@ -157,7 +161,6 @@ def lambda_handler(event, context):
157161
"HardExpiry": False,
158162
}
159163

160-
invoking_event = json.loads(event["invokingEvent"])
161164
rule_parameters = json.loads(event.get("ruleParameters", "{}"))
162165
valid_rule_parameters = evaluate_parameters(rule_parameters, password_assessment_policy)
163166
execution_role_name = valid_rule_parameters.get("ExecutionRoleName", "AWSA-GCLambdaExecutionRole")
@@ -167,9 +170,6 @@ def lambda_handler(event, context):
167170

168171
evaluations = []
169172

170-
if not is_scheduled_notification(invoking_event["messageType"]):
171-
return
172-
173173
aws_config_client = get_client("config", aws_account_id, execution_role_name, is_not_audit_account)
174174
aws_iam_client = get_client("iam", aws_account_id, execution_role_name, is_not_audit_account)
175175

src/lambda/gc12_check_marketplace/app.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ def lambda_handler(event, context):
164164
logger.info("Received Event: %s", json.dumps(event, indent=2))
165165

166166
invoking_event = json.loads(event["invokingEvent"])
167+
if not is_scheduled_notification(invoking_event["messageType"]):
168+
logger.error("Skipping assessments as this is not a scheduled invocation")
169+
return
170+
167171
rule_parameters = json.loads(event.get("ruleParameters", "{}"))
168172
valid_rule_parameters = check_required_parameters(rule_parameters, [])
169173
execution_role_name = valid_rule_parameters.get("ExecutionRoleName", "AWSA-GCLambdaExecutionRole")
@@ -174,10 +178,6 @@ def lambda_handler(event, context):
174178
evaluations = []
175179
interval_between_calls = 0.1
176180

177-
if not is_scheduled_notification(invoking_event["messageType"]):
178-
logger.error("Skipping assessments as this is not a scheduled invocation")
179-
return
180-
181181
aws_config_client = get_client("config", aws_account_id, execution_role_name, is_not_audit_account)
182182
aws_iam_client = get_client("iam", aws_account_id, execution_role_name, is_not_audit_account)
183183
aws_organizations_client = get_client("organizations", aws_account_id, execution_role_name, is_not_audit_account)

0 commit comments

Comments
 (0)