AWS
  • About
  • 수업준비
    • AWS 환경설정
  • 1주차 - EC2
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 2주차 - ELB & Autoscaling
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 3주차 - VPC
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 4주차 - Database
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 5주차 - Storage
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 6주차 - IAM & Security
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 7주차 - Monitoring & Ops
    • 예습
    • 실습
    • AWS Skill Builder
    • 과제
  • 8주차 - DevOps
    • 예습
    • 실습
    • 과제
  • EKS
    • 실습
    • 실습 (AWS Worshop Studio)
  • Serverless
    • 실습
  • FAQ
  • Archive
    • AWS CodeBuild로 애플리케이션 테스트 자동화 시스템 구축
    • AWS CodeDeploy로 애플리케이션 배포 자동화 시스템 구축
      • 배포 실패 수정 방법
Powered by GitBook
On this page

Was this helpful?

  1. Archive
  2. AWS CodeDeploy로 애플리케이션 배포 자동화 시스템 구축

배포 실패 수정 방법

PreviousAWS CodeDeploy로 애플리케이션 배포 자동화 시스템 구축

Last updated 3 years ago

Was this helpful?

1. Deploy 섹션에서 Details를 클릭해서 CodeDeploy 대시보드로 이동

2. Deployment 상태창에서 View events 클릭

3. 실패한 이벤트의 Error Code에 있는 ScriptFailed 클릭

4. 이벤트 로그를 보면 초기 데이터베이스 설정을 할때 데이터베이스에 접근이 안되서 에러가 발생하는것을 확인할수 있습니다.

5. scripts/InitializeDatabase.sh 파일을 보면 Host 값이 localhost로 되어 있습니다.

#!/bin/bash

set -e

cat << EOF | psql -h localhost -U postres
CREATE DATABASE local_library;
CREATE USER local_library WITH PASSWORD 'asdf1234';
GRANT ALL PRIVILEGES ON DATABASE local_library TO local_library;
ALTER USER local_library CREATEDB;
EOF

Host 값을 RDS에 이미 생성되어 있는 locallibrary-prod 인스턴스의 엔드포인트로 바꾸고 어드민 유저이름과 비밀번호는 Secrets Manager에서 prodDatabaseSecret로 시작하는 Secret에서 확인가능합니다. 확인후에 아래와 같이 수정해 주시면 됩니다.

#!/bin/bash

set -e

cat << EOF | PGPASSWORD=<ADMIN_PASSWORD> psql -h <RDS_ENDPOINT> -U <ADMIN_USERNAME>
CREATE DATABASE local_library;
CREATE USER local_library WITH PASSWORD 'asdf1234';
GRANT ALL PRIVILEGES ON DATABASE local_library TO local_library;
ALTER USER local_library CREATEDB;
EOF

6. 추가로 locallibrary/settings.py에 명시한 RDS 엔드포인트도 업데이트 하고 수정한 코드를 GitHub에 반영하면 CodeDeploy로 해당 변경분을 자동으로 배포합니다.

7. 이번에는 ApplicationStart 단계에서 배포가 실패합니다. 로그를 보면 다음과 같습니다.

8. System Manager Session Manager를 통해서 배포가 진행된 EC2 인스턴스에 접속해서 아파치 서버 상태를 보면

[ec2-user@ip-10-0-55-192 ~]$ systemctl status httpd.service -l
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2022-04-07 00:59:20 UTC; 8min ago
     Docs: man:httpd.service(8)
  Process: 23225 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 23225 (code=exited, status=1/FAILURE)

Apr 07 00:59:20 ip-10-0-55-192.ap-northeast-2.compute.internal systemd[1]: Starting The Apache HTTP Server...
Apr 07 00:59:20 ip-10-0-55-192.ap-northeast-2.compute.internal httpd[23225]: httpd: Syntax error on line 362 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/app.conf: Cannot load /root/django-locallibrary-tutorial/venv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so into server: /root/django-locallibrary-tutorial/venv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory
Apr 07 00:59:20 ip-10-0-55-192.ap-northeast-2.compute.internal systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Apr 07 00:59:20 ip-10-0-55-192.ap-northeast-2.compute.internal systemd[1]: Failed to start The Apache HTTP Server.
Apr 07 00:59:20 ip-10-0-55-192.ap-northeast-2.compute.internal systemd[1]: Unit httpd.service entered failed state.
Apr 07 00:59:20 ip-10-0-55-192.ap-northeast-2.compute.internal systemd[1]: httpd.service failed.
[ec2-user@ip-10-0-55-192 ~]$

9. 기존에 개발환경에서 테스트할때는 /root/django-locallibrary-tutorial/venv에 Python 가상환경을 생성했는데 운영환경을 구성할때는 /opt/venv 경로에 가상환경을 생성하면서 아파치 설정파일에서 모듈 및 애플리케이션 소스코드를 찾지 못하고 있어서 발생하는 문제입니다. app.conf에 있는 /root/django-locallibrary-tutorial/venv를 /opt/venv로 /root/django-locallibrary-tutorial를 /opt/django-locallibrary-tutorial 로 수정하고 코드를 GitHub에 반영합니다.

LoadModule wsgi_module "/opt/venv/lib64/python3.7/site-packages/mod_wsgi/server/mod_wsgi-py37.cpython-37m-x86_64-linux-gnu.so"
WSGIPythonHome "/opt/venv"

<Directory /opt/django-locallibrary-tutorial/locallibrary>
    Require all granted
</Directory>

WSGIDaemonProcess locallibrary python-path=/opt/django-locallibrary-tutorial:/opt/venv/lib/python3.7/site-packages
WSGIProcessGroup locallibrary
WSGIScriptAlias / /opt/django-locallibrary-tutorial/locallibrary/wsgi.py