forked from czam01/lambda-serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
25 lines (18 loc) · 767 Bytes
/
lambda_function.py
File metadata and controls
25 lines (18 loc) · 767 Bytes
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
import boto3
import os
from boto3.dynamodb.conditions import Key
DYNAMO_BD = os.environ['DYNAMO_BD']
# Estamos en CloudCamp con el mejor Profe 02 mayo, con correo de aprobacion
#Aprobacion manual
#Juan Carlos por aca
class DynamoAccessor:
def __init__(self, dynamo_table):
dynamo_db = boto3.resource('dynamodb')
self.table = dynamo_db.Table(dynamo_table)
def get_data_from_dynamo(self, cc):
response = self.table.query(KeyConditionExpression=Key('cc').eq(cc))
return response["Items"][0] if any(response["Items"]) else None
def lambda_handler(event, context):
dynamo_backend = DynamoAccessor(DYNAMO_BD)
db_element = dynamo_backend.get_data_from_dynamo(event['cc'])
return db_element