AWS Lambda에서 Django ORM 사용하기

1. AWS Lambda 설정

2) 에러 1

django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.


아래와 같이 수정 완료

# -*- coding: utf-8 -*-
import json
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "just_test.settings")
django.setup()
from datetime import datetime
from django.conf import settings
from django.core.management import execute_from_command_line



2) 에러 2: Did you install mysqlclient?

Test Event Name
importing

Response
{
  "errorMessage": "Error loading MySQLdb module.\nDid you install mysqlclient?",
  "errorType": "ImproperlyConfigured",
  "stackTrace": [
    "  File \"/var/lang/lib/python3.8/imp.py\", line 234, in load_module\n    return load_source(name, filename, file)\n",
    "  File \"/var/lang/lib/python3.8/imp.py\", line 171, in load_source\n    module = _load(spec)\n",
    "  File \"<frozen importlib._bootstrap>\", line 702, in _l

https://stackoverflow.com/questions/55695187/import-libraries-in-lambda-layers

https://stackoverflow.com/questions/50970188/did-you-install-mysqlclient/54200666

https://stackoverflow.com/questions/45992303/using-django-orm-inside-an-aws-lambda-function

3) 작동은 되나, runtime error

메모리 사이즈 문제인 것으로 보인다.

https://stackoverflow.com/questions/59057934/aws-lambda-error-runtime-exited-with-error-signal-killed



4) 간헐적으로, runtime error 발생

람다 함수의 서브넷에 퍼블릭 서브넷 제거
NAT 존재하는 프라이빗 서브넷만 남겨둠

https://stackoverflow.com/questions/51373609/why-aws-lambda-functions-in-a-vpc-sometimes-timeout-and-sometimes-work-fine

하지만

여전히 품절처리 함수가 잘 작동하고, DB에도 적용은 되나,
에러 로그로 나오는 현상 발생
--> 현재 리서치 중

좋은 웹페이지 즐겨찾기