-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathvoting.py
39 lines (33 loc) · 1023 Bytes
/
voting.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
import json
import sys
import logging
import boto3
logging.getLogger().setLevel(logging.DEBUG)
def lambda_handler(event, context):
vote = json.loads(event['body'])['vote']
voter = 'default_voter'
logging.info('Vote: %s, Voter: %s', vote, voter)
try:
publish_vote(vote, voter)
except:
e = sys.exc_info()[0]
logging.error(e)
return {'statusCode': 500, 'body': '{"status": "error"}'}
return {'statusCode': 200, 'body': '{"status": "success"}'}
def publish_vote(vote, voter):
sns = boto3.client('sns', region_name='eu-central-1')
sns.publish(
TopicArn='arn:aws:sns:eu-central-1:971702022395:my-vote',
Message='""',
MessageAttributes={
'vote': {
'DataType': 'String',
'StringValue': vote,
},
'voter': {
'DataType': 'String',
'StringValue': voter,
}
}
)
logging.info('message published')