Open tonykang22 opened 1 year ago
chat_messages
group_id
date_time
chat_groups
chat_members
connection_id
member_username
""" Author | https://github.com/davykiash """ import os import json import boto3 import botocore import requests from datetime import datetime from botocore.exceptions import ClientError from boto3.dynamodb.conditions import Key DYNAMODB_AWS_KEY = os.getenv('DYNAMODB_AWS_KEY') DYNAMODB_AWS_SECRET = os.getenv('DYNAMODB_AWS_SECRET') DYNAMODB_AWS_ENDPOINT = os.getenv('DYNAMODB_AWS_ENDPOINT') def my_handler(event, context): # body = json.loads(event["body"]) # store in dynamodb chat_messages user has joined list_of_groups = get_all_groups() if list_of_groups: return { 'isBase64Encoded': False, 'statusCode': 200, 'headers': {"status": "success"}, 'body': json.dumps(list_of_groups) } else: return { 'statusCode': 200, 'body': "Connection Failed" } def get_all_groups(dynamodb=None): if not dynamodb: dynamodb = boto3.resource('dynamodb', aws_access_key_id=DYNAMODB_AWS_KEY, aws_secret_access_key=DYNAMODB_AWS_SECRET, endpoint_url=DYNAMODB_AWS_ENDPOINT) table = dynamodb.Table('chat_groups') try: response = table.scan() except ClientError as e: print(e.response['Error']['Message']) else: if 'Items' in response.keys(): return response['Items'] else: return None
Deploying a Group Chat App on a Serverless Architecture
서버리스의 장점
서버리스 구축을 위해 필요한 서비스
Amazon S3
Amazon API Gateway
Amazon Lambda
DynamoDB
chat_messages
group_id
date_time
chat_groups
group_id
chat_members
connection_id
member_username
group_id
(group_id-index)CloudFront
흐름
Retrieving the list of groups
Joining and sending messages to all active members in the group.
Leave chat