본문 바로가기
python request time out error 무시하기 개발하다가 로그를 쌓기 위해 request를 날리는데 해당 부분을 비동기로하여 에러를 무시해야 하는 경우가 생겼다 우선 상단에 import requests 라이브러리를 로드하고 try: requests.post("htt",data={"k":k},timeout=0.1) except requests.Timeout: pass except requests.ConnectionError: pass try catch를 이용하여 except pass를 이용한다 2021. 3. 14.
python 람다 애플리케이션 cors 처리하기 python 람다 애플리케이션에서는 return에 cors를 설정해줄 수 있다 cors 뿐만아니라 header status code도 설정이 가능함 return { "statusCode": 200, "body": json.dumps({ "data": { } }, default=str), "headers": Parameters.returnHeaders(), } 저는 class를 만들어서 headers 부분을 정의 해줬습니다 def returnHeaders(self=""): return { "Access-Control-Allow-Headers": "Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token", "Access-Control-All.. 2021. 3. 14.
람다 애플리케이션 메소드별 local, api gateway 데이터 받기 pycharm으로 lambda 애플리케이션을 개발하다보니 로컬과 api gateway에서 event안에 들어있는 구조가 달라 그걸 통합하기 위하여 공통 라이브러리가 필요하다고 판단함 import json class Parameters: def event(event): parameters = '' # local은 resource가 비어 있다 resourcePath = event.get('resource', 'local') if resourcePath == 'local': # local은 event안에 오브젝트 타입으로 데이터가 들어있다 event['serverCheck'] = 'N' result = event return result else: method = event.get('httpMethod') i.. 2021. 3. 6.
람다 Python Signed Url 만들기 S3 + Cloud Front boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudfront.html#examples CloudFront — Boto3 Docs 1.17.18 documentation Id (string) -- [REQUIRED] The unique identifier for the cache policy. If the cache policy is attached to a distribution’s cache behavior, you can get the policy’s identifier using ListDistributions or GetDistribution . If the cache policy is not attach boto3.a.. 2021. 3. 3.
람다 애플리케이션으로 API 개발 pycharm + python3.8 우선 Pycharm으로 Aws Serverless Application를생성하시면 template.yaml이 생성됩니다 해당 template.yaml이 전체적인 컨트롤을 하는데 사용됩니다 우선 구조는 yaml를 빌드하여 lambda 애플리케이션이 생성되고 그 안에 lambda와 layer가 같이 생성 되어 들어 있습니다 그리고 yaml에 적용된 path기준으로 api Gateway가 생성됩니다 알고보면 쉬우나 아무것도 모르고 시작하여 5일정도 소요하여 정리합니다 기본적으로 application이 아닌 hello_world 폴더가 있을겁니다 hello_world > application으로 명칭만 변경하였습니다 application 폴더를 보면 공통적인 데이터를 관리하기 위하여 layer를 구성하였습니다 .. 2021. 2. 18.