-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_count_lambda.py
More file actions
40 lines (28 loc) · 925 Bytes
/
report_count_lambda.py
File metadata and controls
40 lines (28 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import boto3
import os
from common import get_customers_count
def handler(event, context):
print(f"report_customers_handler: {event}")
records = event.get("Records")
new_records_count = len(inserted_records(records))
if(new_records_count == 0):
print('no new records... do not notify')
return
customers_count = get_customers_count()
message = f"""
Records Added: {new_records_count}
Number of records: {customers_count}
"""
publish_report(message)
def inserted_records(records):
return [r for r in records if r.get("eventName") == "INSERT"]
def publish_report(message):
print(f"publishing message {message}")
sns = boto3.client('sns')
topic_arn = os.environ.get('SNS_TOPIC_ARN')
response = sns.publish(
TopicArn=topic_arn,
Message=message,
Subject="[devops-academy] Customers Report"
)
print(response)