-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
45 lines (37 loc) · 1.12 KB
/
update.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
import json
import logging
import os
from actions import decimalencoder
import boto3
# Instanciamos a la BBDD de dynamodb
dynamodb = boto3.resource('dynamodb')
def update(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 update the todo item.")
return
# Instanciamos la tabla
table = dynamodb.Table(os.environ['DYNAMODB_TABLE'])
# Actualizamos/creamos el emparejamiento
result = table.update_item(
Key={
'id': event['pathParameters']['id']
},
ExpressionAttributeNames={
'#id_chat2': 'id_chat2',
},
ExpressionAttributeValues={
':id_chat2': data['chatid'],
},
UpdateExpression='SET #id_chat2 = :id_chat2',
ReturnValues='ALL_NEW',
)
# Devolver el emparejamiento creado
response = {
"statusCode": 200,
"body": json.dumps(result['Attributes'],
cls=decimalencoder.DecimalEncoder)
}
return response