AWS Elastic Beanstalk에 Node.js 프로젝트 올리기

ovovvv·2022년 11월 27일
0

aws

목록 보기
1/3
  1. nest 프로젝트 생성 후
    1.1. 3000 => 8080 포트 변경
    1.2. /.ebextensions/nodecommand.cofig 파일 생성
    1.3. /Procfile 생성
  2. AWS Elastic Beanstalk 애플리케이션 생성
    2.1. 구성 후 소스 파일 업로드

1.1. 포트변경

/src/main.ts

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(8080);
}
bootstrap();

1.2. config 파일 생성

/.ebextensions/nodecommand.config

container_commands:
  01_install:
    command: npm install

1.3. Procfile 생성

/Procfile

run: npm start

Procfile을 찾지 못하면 Beanstalk이 자동으로 server.js 혹은 app.js 파일을 찾아서 실행
codepipeline의 배포스테이지로 Beanstalk을 사용할 때는 Procfile 없어도 됨

2.1. AWS Elastic Beanstalk 애플리케이션 생성





로드밸런싱 사용하려면 고가용성 선택


6분정도 걸림


업로드 후 자동으로 배포 작업 완료

환경으로 이동하면

잘됨 룰루

2022/11/22 10:56:51.482345 [ERROR] An error occurred during execution of command [app-deploy] - [Use NPM to install dependencies]. Stop running the command. Error: Command /bin/sh -c npm --production install failed with error signal: killed. Stderr:npm WARN config production Use `--omit=dev` instead.

배포가 오래걸려 로그 확인이 되지 않거나 로그를 확인했을 때 위와 같은 에러가 뜬다면
설정한 인스턴스의 메모리 용량이 부족해 npm install 명령어가 제대로 실행되지 않은 경우일 수도 있다.
메모리 4GB인 t2.medium으로 바꿔서 해결

During an aborted deployment, some instances may have deployed the new application version. To ensure all instances are running the same version, re-deploy the appropriate application version.

업데이트 할때 수동으로 파일을 직접 업로드 할때 위와 같은 에러가 난다면
업로드하는 zip 파일 명을 이전버전과 다르게 업로드 해야 됨 ex) eb-test.zip => eb-test-v2.zip

그래도 안되는 경우도 있었는데 t2.medium으로 올렸더니 해결
인스턴스 리소스가 모자란데 왜 버전 에러가 뜬지는 나도 몰?루

다음 글
https://velog.io/@ovovvv/AWS-Codepipeline-Elastic-Beanstalk으로-CICD-구성하기

0개의 댓글