AWS Lambda handlers
Requires the lambda extra (awsfindingsmanagerlib[lambda]). See "Running in AWS Lambda" on the home page
for the deployment contract (triggers, environment variables, IAM permissions).
Handlers
lambda_handler
lambda_handler(
_event: dict[str, Any], _context: object
) -> None
Apply all configured suppression rules to every currently matching Security Hub finding.
Raises:
-
RuntimeError–If not all matched findings could be successfully processed. Check the logged warnings above the raised error for which finding(s)/rule(s) were affected.
lambda_handler
lambda_handler(
event: dict[str, Any], _context: object
) -> dict[str, str]
lambda_handler
lambda_handler(
_event: dict[str, Any], _context: object
) -> None
Load the configured rules and place each one on SQS for the worker Lambda to apply.
Reads the destination queue URL from the SQS_QUEUE_URL environment variable.
Raises:
-
Exception–Re-raises any failure to load the rules or send a message to SQS, after logging it.
lambda_handler
lambda_handler(
event: dict[str, Any], _context: object
) -> dict[str, list[dict[str, str]]]
Apply the suppression rule carried by each SQS record to matching Security Hub findings.
Parameters:
-
(eventdict[str, Any]) –The SQS event. Each
event["Records"]entry'sbodyis expected to be a JSON-encoded rules document with exactly one rule in itsRuleslist. -
(_contextobject) –The Lambda context object (unused).
Returns:
Rules loading
load_rules
load_rules(
s3_client: BaseClient | None = None,
) -> dict[str, Any]
Load the rules document, from S3 if configured, otherwise from a local file.
If both the S3_BUCKET_NAME and S3_OBJECT_NAME environment variables are set, the rules
document is loaded from that S3 object. Otherwise, it is loaded from the local file at
RULES_PATH (defaults to rules.yaml).
Parameters:
-
(s3_clientBaseClient, default:None) –The boto3 S3 client to use when loading rules from S3. Only used (and required) when
S3_BUCKET_NAMEandS3_OBJECT_NAMEare both set. Accepting it as a parameter, rather than creating one internally, keeps this function free of AWS calls in unit tests.
Returns:
-
dict[str, Any]–The parsed rules document, expected to contain a top-level
Ruleskey and optionally aManagerConfigkey. Seeawsfindingsmanagerlib.Manager.from_rules_documentfor turning this into a ready-to-useManager.
Raises:
-
ValueError–If S3 loading is configured but no
s3_clientwas provided.
See awsfindingsmanagerlib.Manager.from_rules_document (in "Main top-level functionality") for turning the
loaded document into a ready-to-use Manager.