-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
43 lines (30 loc) · 958 Bytes
/
handler.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
import boto3
import json
import logging
import time
logger = logging.getLogger("handler_logger")
logger.setLevel(logging.DEBUG)
dynamodb = boto3.resource("dynamodb")
DYNAMODB_TABLE_NAME = "serverless-github-collector-table"
def _get_response(status_code, body):
if not isinstance(body, str):
body = json.dumps(body)
return {"statusCode": status_code, "body": body}
def analyze(event, context):
logger.info("analyze requested.")
table = dynamodb.Table(DYNAMODB_TABLE_NAME)
timestamp = int(time.time())
logger.info(str(timestamp))
connectionID = context.aws_request_id
item = {
"connectionID": connectionID,
"repository": "TIL",
"Index": 0,
"Timestamp": timestamp,
"Username": "shinkeonkim",
"Content": "PING!",
}
logger.info(str(item))
table.put_item(Item=item)
logger.info("Item added to database.")
return _get_response(200, "Success")