Skip to content

Commit dafd9dd

Browse files
committed
fix flake8 issues with config rules
1 parent 6896d23 commit dafd9dd

File tree

1 file changed

+23
-4
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/rules/sra_bedrock_check_guardrails

1 file changed

+23
-4
lines changed

aws_sra_examples/solutions/genai/bedrock_org/lambda/rules/sra_bedrock_check_guardrails/app.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""Config rule to check for the existence of guardrails for Bedrock environemts.
2+
3+
Version: 1.0
4+
5+
Config rule for SRA in the repo, https://github.com/aws-samples/aws-security-reference-architecture-examples
6+
7+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
SPDX-License-Identifier: MIT-0
9+
"""
110
from typing import Any
211
import boto3
312
import json
@@ -20,10 +29,20 @@
2029
'contextual_grounding': True
2130
}
2231

23-
# def evaluate_compliance(configuration_item: str, rule_parameters: dict) -> str:
24-
# return 'NOT_APPLICABLE'
2532

26-
def lambda_handler(event: dict, context: Any) -> dict:
33+
def lambda_handler(event: dict, context: Any) -> dict: # noqa: CCR001, C901, U100
34+
"""Lambda handler.
35+
36+
Args:
37+
event (dict): The AWS Config event
38+
context (Any): Lambda context object
39+
40+
Raises:
41+
Exception: Any exception thrown by the lambda function
42+
43+
Returns:
44+
dict: The evaluation results
45+
"""
2746
LOGGER.info("Starting lambda_handler function")
2847
bedrock = boto3.client('bedrock')
2948

@@ -89,7 +108,7 @@ def lambda_handler(event: dict, context: Any) -> dict:
89108
else:
90109
compliance_type = 'NON_COMPLIANT'
91110
annotation = 'No Bedrock guardrails contain all required features. Missing features per guardrail:\n'
92-
for guardrail, missing in non_compliant_guardrails.items(): # type: ignore
111+
for guardrail, missing in non_compliant_guardrails.items(): # type: ignore
93112
annotation += f"- {guardrail}: missing {', '.join(missing)}\n"
94113
LOGGER.info(f"Account is NON_COMPLIANT. {annotation}")
95114

0 commit comments

Comments
 (0)