xncbf / pypy.dev

개인 블로그 저장소
https://pypy.dev
MIT License
1 stars 0 forks source link

serverless/serverless-websocket/ #10

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

python serverless websocket 서버 만들기 1부 | pypy.dev

웹소켓 서버를 serverless 환경으로 선택하는 이유 사전 준비사항 의존성 요구사항 aws credentials 설정 프로젝트 폴더 생성, 의존성 설치 간단한 ping 함수 배포 커넥션을 관리할 Database Websocket connection function 작성 메세지 전송 1부 마무리 웹소켓 서버를 serverless 환경으로 선택하는 이유 절대 서버리스를 sil

https://pypy.dev/serverless/serverless-websocket/

JWSong commented 1 year ago

도움이 많이 되었습니다. 감사합니다!

JWSong commented 1 year ago

몇 가지 수정이 필요 할 것 같습니다.

일단 handler.pydynamodb 선언부가 필요합니다.

# handler.py
import boto3
import logging
import json

logger = logging.getLogger("handler_logger")
logger.setLevel(logging.DEBUG)

dynamodb = boto3.resource("dynamodb")  # 추가 필요
...

그리고 약간의 typo가 있네요.

def send_message(event, message):
    ...
    message = {"content": content} 
    # -> message = {"content": body["content"]}  이렇게 고쳐야 합니다.
    ...

위 사항들만 수정하면 잘 작동합니다.

JWSong commented 1 year ago

여기도 typo가 있네요

import logger  # -> import logging
xncbf commented 1 year ago

@JWSong 으앗 에러가 있었네요 감사합니다! serverless.yml 파일도 예전 버전이다보니 업데이트해야하는 내용들이 있네요 ㅠㅠ

HminiL commented 1 year ago

글 잘보고 있습니다~! 복습중인데 여기도 약간의 typo가 있네요.

logger.debug("Failed: f'{attribute}' not in message dict.")
# -> logger.debug(f"Failed: '{attribute}' not in message dict") 
xncbf commented 1 year ago

@HminiL 엌 감사합니다