Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix consignment indexing lambda sns event parsing #693

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import os
from typing import Any, Dict
Expand Down Expand Up @@ -31,16 +32,21 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> None:
Exception: If `consignment_reference` or `SECRET_ID` are missing.
"""
logger.info("Lambda started")
logger.info("Event received: %s", event)
logger.info("Event received: %s", json.dumps(event))

sns_message = json.loads(event["Records"][0]["Sns"]["Message"])
consignment_reference = sns_message.get("parameters", {}).get("reference")

if not consignment_reference:
error_message = "Missing reference in SNS Message required for indexing"
logger.error(error_message)
raise Exception(error_message)

# Extract parameters from the event and environment variables
consignment_reference = event.get("parameters", {}).get("reference")
secret_id = os.getenv("SECRET_ID")

# Validate required parameters
if not consignment_reference or not secret_id:
if not secret_id:
error_message = (
"Missing consignment_reference or SECRET_ID required for indexing"
"Missing SECRET_ID environment variable required for indexing"
)
logger.error(error_message)
raise Exception(error_message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import os
from typing import Any, Dict, Tuple
Expand All @@ -12,8 +13,7 @@

def lambda_handler(event: Dict[str, Any], context: Any) -> None:
logger.info("Lambda started")
logger.info("Event:")
logger.info(event)
logger.info("Event received: %s", json.dumps(event))
bucket_name, object_key = _extract_s3_event_info(event)
secret_id = os.getenv("SECRET_ID")
index_file_content_and_metadata_in_opensearch_from_aws(
Expand Down
Loading