Skip to content

Commit 86b5324

Browse files
committed
working on access denied / encrypted guardrail issue
1 parent 1396295 commit 86b5324

File tree

1 file changed

+4
-1
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/rules/sra_bedrock_check_guardrail_encryption

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Any
1414

1515
import boto3
16+
from botocore.exceptions import ClientError
1617

1718
# Setup Default Logger
1819
LOGGER = logging.getLogger(__name__)
@@ -58,7 +59,9 @@ def evaluate_compliance(rule_parameters: dict) -> tuple[str, str]: # noqa: CFQ0
5859
return "NON_COMPLIANT", f"The following Bedrock guardrails are not encrypted with a KMS key: {', '.join(unencrypted_guardrails)}"
5960
return "COMPLIANT", "All Bedrock guardrails are encrypted with a KMS key"
6061

61-
except Exception as e:
62+
except ClientError as e:
63+
if e.response['Error']['Code'] == 'AccessDeniedException':
64+
return "NON_COMPLIANT", "Access denied to Bedrock guardrails. If encryption is enabled, ensure the IAM role has the necessary permissions to use the KMS key."
6265
LOGGER.error(f"Error evaluating Bedrock guardrails encryption: {str(e)}")
6366
return "ERROR", f"Error evaluating compliance: {str(e)}"
6467

0 commit comments

Comments
 (0)