-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.py
39 lines (31 loc) · 875 Bytes
/
create.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 logging
import os
import uuid
import boto3
# Instanciamos a la BBDD de dynamodb
dynamodb = boto3.resource('dynamodb')
def create(event, context):
# Extraemos y verificamos los datos de entrada
data = json.loads(event['body'])
if 'chatid' not in data:
logging.error("Validation Failed")
raise Exception("Couldn't create the todo item.")
# Instanciamos la tabla
table = dynamodb.Table(os.environ['DYNAMODB_TABLE'])
# Generamos el token
token = str(uuid.uuid1())
# Creamos el objeto a almacenar en la BBDD
item = {
'id': token,
'id_chat1': data['chatid'],
'id_chat2': "",
}
# Escribimos el objeto en la BBDD
table.put_item(Item=item)
# Respondemos al cliente
response = {
"statusCode": 200,
"body": token
}
return response