-
Notifications
You must be signed in to change notification settings - Fork 1
/
LambdaStartInitialCall.py
57 lines (44 loc) · 1.74 KB
/
LambdaStartInitialCall.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import boto3
import datetime
import json
from botocore.vendored import requests
#init boto
client = boto3.client('connect',region_name='your region')
dynamodb = boto3.resource('dynamodb', region_name='your region', endpoint_url="your endpoint")
#Get devide and date/time
now = datetime.datetime.now()
print("time: ",now)
date = now.strftime("%Y-%m-%d")
hour = now.strftime("%H:%M")
deviceid = "your device id" #It can be extracted from event.serialnumber, if you are using more than 1 device
def lambda_handler(event, context):
# Call designated person because he/she pressed the button. Use Amazon Connect API
response = client.start_outbound_voice_contact(
DestinationPhoneNumber='designated phone number',
ContactFlowId='contact flow number',
InstanceId='Instance ID',
SourcePhoneNumber='source number in Amazon Connet'
)
# Enrich with weather data
response = requests.get("call a public api to get weather, like for example dark sky")
data = response.json()
weatherdata = data['currently']['summary']
temperdata = int(data['currently']['temperature'])
# Enrich with moon data
response = requests.get("call a public api to get moon data, like for example US Navy")
data = response.json()
moondata = data['closestphase']['phase']
#Updating DynamoDB Table
table = dynamodb.Table('your table name')
response = table.put_item(
Item={
'deviceid': deviceid,
'date': date,
'hour': hour,
'CallActive': 'Y',
'Weather': weatherdata,
'Temperature': temperdata,
'MoonPhase': moondata,
}
)
return 'Call performed, DynamoDB alarm is active.'