def lambda_handler(event, context): body = json.loads(event['body']) print("body", body) emailIds = body['emailIds'] emailIds.append(body['ownerEmailID']) acceptedUsers, rejectedEmails = validatePersonsByEmailIds(emailIds) print("accepted") print(acceptedUsers) groupId = str(uuid.uuid1()) print(groupId) addGroupToAcceptedPersons(acceptedUsers, groupId) if not body['description']: body['description'] = " " groupEntry = { "groupId": groupId, "groupName": body['groupName'], "description": body['description'], "owner": body['ownerID'], "people": acceptedUsers, "documentIds": [] } persist_to_dynamo('groups', groupEntry) return { 'statusCode': 200, 'body': json.dumps(groupEntry), 'headers': { 'Access-Control-Allow-Origin': "*", "Access-Control-Allow-Credentials": "true" } }
def persist_to_pages(documentId, index, pageId, image_name): page = { "pageId": pageId, "pageNumber": index, "url": s3_base_url + image_name, "documentId": documentId, "commentIds": [], "status": "DRAFT" } persist_to_dynamo('pages', page) print("Persisted to pages for pageId", pageId)
def persist_to_documents(event, pageIds): document = { "documentId": event['documentID'], "name": event['documentName'], "ownerId": event['ownerId'], "description": event['description'], "groupIds": event['groupIds'], "pageIds": pageIds, "status": "DRAFT" } persist_to_dynamo('documents', document) print("Persisted to documents for documentId", event['documentID'])
def lambda_handler(event, context): # TODO implement # if not validateParameters(event['pageId'],event['userId']): # return { # 'statusCode': 401, # 'body': 'User unauthorized to access this page', # 'headers': { # 'Access-Control-Allow-Origin': "*", # "Access-Control-Allow-Credentials": "true" # } # } commentId = str(uuid.uuid1()) time_now = str(time.time()) event = json.loads(event['body']) pageId = event['pageId'] commentEntry = { "commentId": commentId, "pageId": pageId, "comment": event['comment'], "time": time_now, "userId": event['userId'] } # add entry in comments persist_to_dynamo('comments', commentEntry) # update commentIds in pages addToPagesCollection(pageId, commentId) # add to elastic addToElastic(pageId, commentId, event['comment'], time_now) dynamodb = boto3.resource('dynamodb', region_name="us-east-1") peopleTable = dynamodb.Table('persons') person = peopleTable.get_item(Key={"personId": event['userId']}) commentEntry['userName'] = person['Item']['name'] return { 'statusCode': 200, 'body': json.dumps(commentEntry), 'headers': { 'Access-Control-Allow-Origin': "*", "Access-Control-Allow-Credentials": "true" } }
def lambda_handler(event, context): # The event structure is described below # Pre sign up handler should put all necessary information onto dynamoDB """ event { 'version': '1', 'region': 'us-east-1', 'userPoolId': 'us-east-1_rpUsHwFI1', 'userName': '******', 'callerContext': { 'awsSdkVersion': 'aws-sdk-unknown-unknown', 'clientId': '1962ro47nqjq5nreds0et30e6a' }, 'triggerSource': 'PreSignUp_ExternalProvider', 'request': { 'userAttributes': { 'cognito:email_alias': '', 'cognito:phone_number_alias': '', 'given_name': 'shashank', 'email': '*****@*****.**' }, 'validationData': {} }, 'response': { 'autoConfirmUser': False, 'autoVerifyEmail': False, 'autoVerifyPhone': False } }""" if not checkIfExist(event['userName']): personInfo = { "personId": event['userName'], "name": event['request']['userAttributes']['given_name'], "email": event['request']['userAttributes']['email'], "groupId": [] } persist_to_dynamo('persons', personInfo) # DO NOT CHANGE, Cognito requires event to be returned to complete successful sign up return event