-
Notifications
You must be signed in to change notification settings - Fork 0
/
second_lambda.py
42 lines (29 loc) · 1.07 KB
/
second_lambda.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
import json
# import boto3 #TODO uncomment in lambda
# this library allows interaction with AWS services
from time import gmtime, strftime
import uuid
from sudoku_solver import SudokuSolver
#TODO uncomment in lambda
# dynamodb = boto3.resource('dynamodb')
# table = dynamodb.Table('SudokuResults2')
now = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
def lambda_handler(event, context):
correct_sudoku_str = event['body']['data']
solved_sudoku = SudokuSolver(correct_sudoku_str).solved_sudoku
#TODO uncomment in lambda
# item_id = str(uuid.uuid4()) # create unique key for id
# table.put_item( # add solution to the database
# Item={
# 'ID': item_id,
# 'result': str(solved_sudoku),
# 'resultTimestamp': now
# }
# )
response_body = {'sudoku': solved_sudoku}
response = {
'statusCode': 200,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps(response_body)
}
return response