Skip to content

Feature/sqs#360

Open
sliu008 wants to merge 20 commits into
developfrom
feature/sqs
Open

Feature/sqs#360
sliu008 wants to merge 20 commits into
developfrom
feature/sqs

Conversation

@sliu008

@sliu008 sliu008 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

This pull request migrates the CNM (Collection Notification Message) and granule loading workflow from using direct Lambda invocations via SNS to a decoupled, queue-based architecture using Amazon SQS. This improves reliability, scalability, and error handling for message processing between components. The changes update both the application logic and Terraform infrastructure to support this new design.

Key changes include:

Infrastructure: Migration to SQS-based Messaging

  • Introduced new SQS queues and dead letter queues for both CNM and granule load messages, including event source mappings to trigger the respective Lambda functions from SQS instead of SNS or direct Lambda invocation. (terraform/hydrocron-sqs.tf)
  • Updated the SNS topic subscription to deliver CNM messages to the SQS queue (hydrocron_cnm_queue) instead of directly invoking the Lambda. (terraform/hydrocron-sns.tf)
  • Updated environment variables and IAM roles/policies to support SQS access, including permissions for sending messages and consuming from SQS. (terraform/hydrocron-lambda.tf, terraform/hydrocron-iam.tf) [1] [2] [3] [4] [5]

Application Logic: Decoupling and SQS Integration

  • Refactored the CNM handler to send granule load messages to SQS instead of invoking the granule load Lambda directly, and updated the granule handler to process messages from SQS. (hydrocron/db/load_data.py) [1] [2] [3]
  • Updated S3 file download calls to include the RequestPayer: requester argument for compatibility with requester-pays buckets. (hydrocron/db/io/swot_shp.py) [1] [2]

Dependency Updates

  • Added aiohttp as a new dependency in the Python project configuration. (pyproject.toml)

@sliu008 sliu008 requested a review from jamesfwood June 15, 2026 19:18
@tloubrieu-jpl tloubrieu-jpl moved this to needs:triage in podaac Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the CNM (Collection Notification Message) → granule loading flow from direct Lambda invocation to an SQS-based, decoupled architecture, and updates both Terraform and application code to support queue-triggered processing and DLQs.

Changes:

  • Added CNM and granule SQS queues + DLQs and wired Lambda event source mappings (SQS → Lambdas).
  • Updated SNS CNM response delivery to target SQS instead of invoking the CNM Lambda directly.
  • Refactored cnm_handler to enqueue granule-load work items to SQS; updated granule handler to accept SQS event shapes; added requester-pays args to S3 downloads; added aiohttp dependency.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
terraform/hydrocron-sqs.tf Introduces CNM + granule SQS queues, DLQs, queue policy for SNS→SQS, and event source mappings.
terraform/hydrocron-sns.tf Switches CNM SNS subscription protocol from lambda to sqs (raw delivery enabled).
terraform/hydrocron-lambda.tf Updates CNM lambda env var to GRANULE_QUEUE_URL; removes direct invoke permission from CNM to granule lambda.
terraform/hydrocron-iam.tf Adds SQS send policy for CNM lambda; adds SQS execution managed policy for granule loader role; removes SNS→Lambda permission.
hydrocron/db/load_data.py Updates handlers for SQS event shapes; CNM handler now sends granule-load messages to SQS.
hydrocron/db/io/swot_shp.py Adds RequestPayer=requester to S3 download_file calls.
pyproject.toml Adds aiohttp dependency.
CHANGELOG.md Documents the SQS migration and requester-pays change (wording needs cleanup).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hydrocron/db/load_data.py
Comment on lines +98 to +102
if 'Records' in event:
record = json.loads(event['Records'][0]['body'])
body = record['body']
else:
body = event['body']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests

Comment thread hydrocron/db/load_data.py
Comment on lines 173 to +211
@@ -186,19 +192,23 @@ def cnm_handler(event, _):
else:
raise MissingTable(f"Error: Cannot load granule: {granule_uri}")

event2 = ('{"body": {"granule_path": "' + granule_uri
+ '","table_name": "' + table_name
+ '","track_table": "' + track_table
+ '","checksum": "' + checksum
+ '","revisionDate": "' + revision_date
+ '","load_benchmarking_data": "' + load_benchmarking_data + '"}}')

logging.info("Invoking granule load lambda with event json %s", str(event2))

lambda_client.invoke(
FunctionName=os.environ['GRANULE_LAMBDA_FUNCTION_NAME'],
InvocationType='Event',
Payload=event2)
msg_body = json.dumps({
"body": {
"granule_path": granule_uri,
"table_name": table_name,
"track_table": track_table,
"checksum": checksum,
"revisionDate": revision_date,
"load_benchmarking_data": load_benchmarking_data
}
})

logging.info("Sending granule load message to SQS: %s", msg_body)

sqs_client.send_message(
QueueUrl=queue_url,
MessageBody=msg_body
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests

Comment on lines 49 to 54
if filepath.startswith('s3'):
bucket_name, key = filepath.replace("s3://", "").split("/", 1)
logging.info("Opening granule %s from bucket %s", key, bucket_name)

s3_resource.Bucket(bucket_name).download_file(key, lambda_temp_file)
s3_resource.Bucket(bucket_name).download_file(key, lambda_temp_file, ExtraArgs={"RequestPayer": "requester"})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added tests

Comment thread pyproject.toml
Comment on lines 29 to 33
moto = "^5.0.9"
vcrpy = "^8.0.0"
python-cmr = "^0.13.0"
aiohttp = "3.13.5"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aiohttp latest breaks another library so im pinning it to the newest one possible

Comment thread CHANGELOG.md Outdated
Comment thread CHANGELOG.md
@tloubrieu-jpl

Copy link
Copy Markdown
Contributor

Hi @sliu008 , @jamesfwood , do we have an issue to track that activity ?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: needs:triage

Development

Successfully merging this pull request may close these issues.

4 participants