Skip to content

Commit ec522c0

Browse files
committed
fix flake8 issues for config rules
1 parent 5848842 commit ec522c0

File tree

1 file changed

+28
-5
lines changed
  • aws_sra_examples/solutions/genai/bedrock_org/lambda/rules/sra_bedrock_check_cloudwatch_endpoints

1 file changed

+28
-5
lines changed

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""Config rule to check CloudWatch endpoints 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
@@ -17,8 +26,16 @@
1726
ec2_client = boto3.client('ec2', region_name=AWS_REGION)
1827
config_client = boto3.client('config', region_name=AWS_REGION)
1928

29+
2030
def evaluate_compliance(vpc_id: str) -> tuple[str, str]:
21-
"""Evaluates if a CloudWatch gateway endpoint is in place for the given VPC"""
31+
"""Evaluate if a CloudWatch gateway endpoint is in place for the given VPC.
32+
33+
Args:
34+
vpc_id: The ID of the VPC to evaluate
35+
36+
Returns:
37+
A tuple containing the compliance status and annotation message
38+
"""
2239
try:
2340
response = ec2_client.describe_vpc_endpoints(
2441
Filters=[
@@ -28,18 +45,24 @@ def evaluate_compliance(vpc_id: str) -> tuple[str, str]:
2845
)
2946

3047
endpoints = response['VpcEndpoints']
31-
48+
3249
if endpoints:
3350
endpoint_id = endpoints[0]['VpcEndpointId']
3451
return 'COMPLIANT', f"CloudWatch gateway endpoint is in place for VPC {vpc_id}. Endpoint ID: {endpoint_id}"
35-
else:
36-
return 'NON_COMPLIANT', f"No CloudWatch gateway endpoint found for VPC {vpc_id}"
52+
return 'NON_COMPLIANT', f"No CloudWatch gateway endpoint found for VPC {vpc_id}"
3753

3854
except Exception as e:
3955
LOGGER.error(f"Error evaluating CloudWatch gateway endpoint for VPC {vpc_id}: {str(e)}")
4056
return 'ERROR', f"Error evaluating compliance: {str(e)}"
4157

42-
def lambda_handler(event: dict, context: Any) -> None:
58+
59+
def lambda_handler(event: dict, context: Any) -> None: # noqa: U100
60+
"""Lambda handler. This function is triggered by AWS Config when evaluating compliance.
61+
62+
Args:
63+
event (dict): Lambda event object
64+
context (Any): Lambda context object
65+
"""
4366
LOGGER.info('Evaluating compliance for AWS Config rule')
4467
LOGGER.info(f"Event: {json.dumps(event)}")
4568

0 commit comments

Comments
 (0)