-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnomalyMessageDeliveryFunction.py
35 lines (25 loc) · 1.32 KB
/
AnomalyMessageDeliveryFunction.py
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
import json
import os
import boto3
from boto3.dynamodb.conditions import Key, Attr
dynamodb = boto3.resource('dynamodb')
sns = boto3.client('sns')
output_table = os.environ.get('OUTPUT_TABLE_NAME')
sns_topic_arn = os.environ.get('SNS_TOPIC_ARN')
def handler(event, context):
table = dynamodb.Table(output_table)
ddb_response = table.scan(FilterExpression=Attr('anomaly_score').gte('3'))
items = ddb_response['Items']
for item in items:
location = item['location']
wind_speed = item['max_wind_speed']
message = '''\
Abnormal wind turbine speed detected for {location} with a wind speed of {wind_speed}.
NOTE: As per National Wind Watch, every wind turbine has a range of wind speeds, typically around 30 to 55 mph, in which it will produce maximum capacity. When wind is more than 70 mph, it is important to start shutdown procedures in order to protect the turbine from high wind.\
'''.format(location=location, wind_speed=wind_speed)
sns_response = sns.publish(
TargetArn=sns_topic_arn,
Message=(message),
Subject='Abnormal Wind Turbine Speed Detected'
)
print(f"Abnormal wind turbine speed detected for {location} with a wind speed of {wind_speed}.")