Skip to content

Commit fcdb3ab

Browse files
committed
CMR-10313: updating PR requests.
1 parent f508813 commit fcdb3ab

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

subscription/notify-lambda/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# This script is used by the bamboo build project.
2-
31
#!/bin/bash
2+
# This script is used by the bamboo build project.
43

54
mkdir -p package
65

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22

33
export PYTHONPATH=src
4-
#export AWS_REGION="us-east-1"
54

65
pip3 install requests
76
python3 -m unittest discover -v -s ./test -p "*_test.py"

subscription/notify-lambda/src/notification_lambda.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
import requests
33
from logger import logger
44

5-
# This lambda is triggered through a subscription to the cmr-internal-subscription-sit SNS topic. It processes the events which are notifications that get sent
5+
# This lambda is triggered through a subscription to the cmr-internal-subscription-<env> SNS topic. It processes the events which are notifications that get sent
66
# to an external URL.
77

8-
# Lambda's cannot handle Type hints in some cases. They are left as comments.
9-
# handler(event: Dict[str, Any], context: Any) -> None:
108
def handler(event, context):
11-
"""The handler is the starting point that is triggered by an SNS topic subscription with a filter that designates tha the notification sent is a URL notification. """
9+
"""The handler is the starting point that is triggered by an SNS topic subscription with a filter that designates tha the notification sent is a URL notification.
10+
Input: event: Dict[str, Any], context: Any
11+
Returns: None"""
1212

1313
logger.debug(f"Ingest notification lambda received event: {json.dumps(event, indent=2)}")
1414
for record in event['Records']:
1515
process_message(record)
1616

17-
# process_message(record: Dict[str, Any]) ->None:
1817
def process_message(record):
19-
"""Processes the record in the event. """
18+
"""Processes the record in the event.
19+
Input: record: Dict[str, Any]
20+
Returns: None"""
2021

2122
try:
2223
logger.info(f"Ingest notification lambda processing message - record: {record}")
@@ -29,9 +30,11 @@ def process_message(record):
2930
logger.error(f"Ingest notification lambda an error occurred {e} while trying to send the record: {record}")
3031
raise e
3132

32-
# send_message(url: str, message: Dict[str, Any]) -> None:
3333
def send_message(url, message):
34-
"""Sends the passed message to the external URL. If not successful the message is put onto a dead letter queue."""
34+
"""Sends the passed message to the external URL. If not successful the message is put onto a dead letter queue.
35+
Input: url: str, message: Dict[str, Any]
36+
Returns: None"""
37+
3538
# Prepare the data to be sent
3639

3740
try:

subscription/notify-test-lambda/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ This lambda is a test lambda meant to be run in SIT and WL.
33
A user creates an ingest granule subscription. An example follows:
44
{"Name": "Ingest-Subscription-Test-Sit-http",
55
"Type": "granule",
6-
"SubscriberId": "eereiter",
6+
"SubscriberId": "user1",
77
"CollectionConceptId": "C1200463968-CMR_ONLY",
8-
"EndPoint": "http://internal-cmr-services-sit-internal-only-2141831226.us-east-1.elb.amazonaws.com:80/notification/tester",
8+
"EndPoint": "http://<the-internal-loadbalancer-url>/notification/tester",
99
"Mode": ["New", "Update", "Delete"],
1010
"Method": "ingest",
1111
"MetadataSpecification": {
@@ -19,8 +19,8 @@ Make sure the URL is the CMR internal load balancer followed by /notification/te
1919

2020
Ingest a granule.
2121

22-
To verify that the notification is correct and that it was sent tunnel into the CMR internal load balancer
23-
then issue a get request to the load balancer with the correct tunnel port number such as
22+
To verify that the notification is correct and that it was sent through the tunnel into the CMR internal load balancer,
23+
issue a get request to the load balancer with the correct tunnel port number such as
2424

2525
curl http://localhost:8081/notification/tester
2626

@@ -33,20 +33,20 @@ curl -XPOST -H "Content-Type: application/json" http://localhost:8081/notificati
3333
{
3434
"EventSource": "aws:sns",
3535
"EventVersion": "1.0",
36-
"EventSubscriptionArn": "arn:aws:sns:us-east-1:832706493240:cmr-subscriptions-sit:1f071817-9e7b-450e-b5a5-606bef7c5b71",
36+
"EventSubscriptionArn": "arn:aws:sns:<region>:<account>:<SNS name>:<unique ID>",
3737
"Sns": {
3838
"Type": "Notification",
3939
"MessageId": "ed8c7ee0-c70a-5050-8ef9-1effe57d3dde",
40-
"TopicArn": "arn:aws:sns:us-east-1:832706493240:cmr-subscriptions-sit",
40+
"TopicArn": "arn:aws:sns:<region>:<account>:<sns name>",
4141
"Subject": "testing again",
4242
"Message": "testing again",
4343
"Timestamp": "2025-02-06T20:48:55.564Z",
4444
"SignatureVersion": "1",
45-
"Signature": "iNvFhB7SvB2Um4xkJ4czhaDtQ9WMr3VWz91j9aBJclHQOSR1vznwdT6pJLJOj1fUA/C9JatNEnouUiPut+8DACZ8pVXfMw5bvHoyci63Y7z5gcmVIHpEMetn1Ms7SpgnuddrIoKpCN/tAQGrEfmzDlMbTXjRWrXpEs8xXsJ+Xq2Mp17FoMU00/JV/eAP8ktHX7TtS+dBGLsPd/QPY3eN5QYcmYAcoFd99Va4Qt6dMqOoH/fjIs1aCwnmD02MSnbjCWOgNSteZChnVAT/+l26krKoidHSop53guPt5KWNBGXTSy4Ouhq630qourN+AiVbKqzUtVypNTXas7iBEoT5Nw==",
46-
"SigningCertUrl": "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-9c6465fa7f48f5cacd23014631ec1136.pem",
47-
"UnsubscribeUrl": "https://sns.us-east-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:832706493240:cmr-subscriptions-sit:1f071817-9e7b-450e-b5a5-606bef7c5b71",
45+
"Signature": "iN...TXas7iBEoT5Nw==",
46+
"SigningCertUrl": "https://sns.<region>.amazonaws.com/SimpleNotificationService-9...6.pem",
47+
"UnsubscribeUrl": "https://sns.<region>.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=<subscription arn>",
4848
"MessageAttributes": {
49-
"endpoint": "http://host.docker.internal:5001/store"
49+
"endpoint": "URL"
5050
}
5151
}
5252
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
boto3
2+

subscription/notify-test-lambda/src/notify-test-lambda.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import json
22
import boto3
33
from botocore.exceptions import ClientError
4+
from sys import stdout
45

56
# This lambda is to be used in SIT and WL to test the ingest subscription notification process.
67
# This is a test lambda that gets triggered off of the interal CMR load balancer.
78
# It receives a notification generated by the ingest notification lambda.
8-
# The notification is stored in a file in an S3 bucket. Ussers can tunnel into the CMR internal only
9+
# The notification is stored in a file in an S3 bucket. Users can tunnel into the CMR internal only
910
# load balancer and run curl http://localhost:8081/notification/tester. Make sure to use the correct port number
1011
# that you used in your tunnel.
1112

@@ -55,6 +56,7 @@ def handle_post(body):
5556
}
5657
except Exception as e:
5758
print(f"Error in POST: {str(e)}")
59+
stdout.flush()
5860
return {
5961
'statusCode': 500,
6062
'body': json.dumps('Error saving data')
@@ -79,6 +81,7 @@ def handle_get():
7981
}
8082
else:
8183
print(f"Error in GET: {str(e)}")
84+
stdout.flush()
8285
return {
8386
'statusCode': 500,
8487
'body': json.dumps('Error retrieving data')

0 commit comments

Comments
 (0)