|
| 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 | +""" |
1 | 10 | from typing import Any |
2 | 11 | import boto3 |
3 | 12 | import json |
|
20 | 29 | 'contextual_grounding': True |
21 | 30 | } |
22 | 31 |
|
23 | | -# def evaluate_compliance(configuration_item: str, rule_parameters: dict) -> str: |
24 | | -# return 'NOT_APPLICABLE' |
25 | 32 |
|
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 | + """ |
27 | 46 | LOGGER.info("Starting lambda_handler function") |
28 | 47 | bedrock = boto3.client('bedrock') |
29 | 48 |
|
@@ -89,7 +108,7 @@ def lambda_handler(event: dict, context: Any) -> dict: |
89 | 108 | else: |
90 | 109 | compliance_type = 'NON_COMPLIANT' |
91 | 110 | 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 |
93 | 112 | annotation += f"- {guardrail}: missing {', '.join(missing)}\n" |
94 | 113 | LOGGER.info(f"Account is NON_COMPLIANT. {annotation}") |
95 | 114 |
|
|
0 commit comments