본문 바로가기

코딩-AWS

[Django] django AWS RDS 올바르게 연결하기 [오류포함]

728x90
반응형

아 진짜 이거 2시간 애먹었다... 퇴근하고 여태 붙잡고있다가 Stackexchange에서 보고 해결했다..

먼저 이오류!! 사람잡는다.

 

django.db.utils.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "jldb-xxx.c1cn96452cds.ap-northeast-2.rds.amazonaws.com" (3.35.123.4) and accepting TCP/IP connections on port 5432?

 

 

1.먼저 settings py에 해당 데이터베이스 설정을 해준다.

#SETTINGS.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'HOST': 'jldb-xxx.c1cn96452cds.ap-northeast-2.rds.amazonaws.com',
        'PORT': '5432',
        'NAME': 'postgres', # <-----이부분 중요 !! db인스턴스명이 아니라 유저이름과 동일하게 SET!
        'USER': 'postgres',
        'PASSWORD': 'daco0303',
    }
}


2. AWS RDS 에서 인스턴스 생성.

 

중요! 보안그룹을 새로 만들고(처음 시작할 시) 퍼블릭 엑세스 가능성을 '예'로 설정


3. RDS생성후 생성된 VPC를 클릭

0.0.0.0/24 로 퍼블릭 엑세스 설정 + 내IP 를 인바운드 규칙에 포함시켜줘야 외부에서 RDS 접속이 가능하다.


4. python manage.py migrate  CMD창에 입력


Operations to perform:
  Apply all migrations: admin, auth, contenttypes, photographist, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK        
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying photographist.0001_initial... OK
  Applying sessions.0001_initial... OK

성공!!

728x90
반응형