관리 메뉴

공부 기록장 💻

[AWS] Elastic Beanstalk를 이용한 간단한 Java Spring Boot 웹 애플리케이션 환경 생성 및 설정과 배포 (Deploy Spring Boot Web Application with AWS Elastic Beanstalk) 본문

# Tech Studies/AWS

[AWS] Elastic Beanstalk를 이용한 간단한 Java Spring Boot 웹 애플리케이션 환경 생성 및 설정과 배포 (Deploy Spring Boot Web Application with AWS Elastic Beanstalk)

dream_for 2023. 1. 25. 13:50

 

 

 

AWS 에서 제공하는 Elastic Beanstalk 서비스를 이용하여 Java의 내부 메모리를 이용하여 데이터베이스를 대체한, 간단한 Java Spring Boot 기반 회원 예제 서비스 애플리케이션을 배포해보자. 

이 글은 medium에서 작성된 이 기술 블로그 글 을 참고하였다.

 

 

우선 배포하고자 하는 Spring Boot 애플리케이션의 application.properties에서 server.port=5000 을 적어주자.

(AWS EB 공식 문서 에 의하면, Elastic Beanstalk은 Apache HTTPD를 역방향 프록시를 사용하여 애플리케이션 포트 80의 Elastic Load Balancing 로드 밸런서에 매핑한다. 기본적으로 Elastic Beanstalk은 요청을 포트 5000의 애플리케이션에 전달하도록 프록시 서버를 구성하므로, PORT 환경 속성을 EB가 수신 대기하는 5000으로 설정하여 기본 포트를 재정의하도록 하자.)

 

 

 

이제 Elastic Beanstalk 서비스 제공 사이트에 들어가, 우측 상단의 Create Application 을 클릭하자.

 

 

 

 

Elastic Beanstalk 웹 애플리케이션 생성하기

 

웹 앱 생성

애플리케이션 정보, 태그

 

다음과 같이 웹 앱 생성 페이지가 뜬다.

애플리케이션 정보의 애플리케이션 이름에, 해당 프로젝트를 잘 나타낼 수 있는 이름을 작성해주자.

(이전에 node.js 애플리케이션을 생성하며 캡처했던 사진으로 대체)

애플리케이션 태그에는 리소스를 그룹화하고 필터링 할 수 있는 키와 값들을 적어주도록 하자. (스킵 가능)

 

 

 

환경 정보

 

이제 환경 정보을 구성하자.

애플리케이션 이름 Spring-test에 해당하는 환경 정보의 이름을 잘 나타낼 수 있는 이름을 작성해주도록 하자.

 

 

 

플랫폼

 

Spring Boot Application을 띄울 것이기 때문에, 플랫폼으로는 Java를 선택하고 플랫폼 브랜치 Corretto 17 running on 64bit Amazin Linux 2, 플랫폼 버전3.4.3 (Recommended) 를 선택하자.

 

 

애플리케이션 코드

직접 Spring Boot 프로젝트 압축 파일을 업로드 할 것이기 때문에, 애플리케이션 코드 타입으로는 코드 업로드 를 선택하자.

이후 버전 레이블을 고유한 버전 이름으로 작성한 후, 소스 코드 오리진로컬 파일 을 선택 한 후에, 

Spring boot 프로젝트를 빌드하여 생성한 jar 파일을 업로드 하도록 하자.

 

 

위의 모든 과정을 마치고, 애플리케이션 생성 을 클릭하도록 하자.

 

 

애플리케이션 생성 완료, 대시보드 확인

 

이제 애플리케이션 생성을 마쳤다. 약 5분정도의 시간이 지나면, 모든 환경 설정이 적용되며 다음과 같이 확인 상태실행 버전, 플랫폼 정보를 확인할 수 있다.

아래에는 최근 이벤트 가 표시되며, 인스턴스 배포 진행 상황과 환경 health check 정보 이벤트 등이 나타난다.

 

 

배포 링크 확인

 

이제 배포된 링크로 들어가보면, 회원 예제 프로젝트에서 만들었던 Web View가 나타나는 것을 확인할 수 있다.

 

 

 

이번엔 회원 가입  버튼을 눌러,  /members/new 경로로 들어가보면 다음의 화면이 나타난다. 

간단하게 등록해보자.

 

 

 

/members 경로로 들어가보니, 만들어 놓았던 객체들이 잘 나타나는 것을 확인할 수 있다.

 

 

모바일 환경에서도 역시나, 잘 나타난다.

 

 

 

대시보드 확인

이제 만들어놓은 환경의 대시보드들을 확인해보자.

 

 

 

최근 환경

지금까지 구성해왔던 전체 환경 목록을 확인할 수 있다.

 

All Environments
See your existing Elastic Beanstalk environments across applications in this AWS Region. Manage environments and add new ones.

An environment is a collection of AWS resources running an application version. When you create an environment, Elastic Beanstalk provisions the resources needed to run the application version you specified.

Things you can do on this page:

  • Create an environment.
  • Select an environment to perform actions on it.
  • Choose an environment or an application name to go to its page.
  • Choose an environment URL to go to your web application's website.
  • Set page preferences (choose the settings icon).

 

모든 애플리케이션

AWS에서 만든 Elastic Beanstalk 애플리케이션들을 모두 확인할 수 있다.

 

All applications
See your existing Elastic Beanstalk applications in this AWS Region. Manage applications and add new ones.
An Elastic Beanstalk application is a logical collection of Elastic Beanstalk components, including environments, application versions, and saved configurations. In Elastic Beanstalk an application is conceptually similar to a folder.
Things you can do on this page:
Create an application.Select an application to perform actions on it.Choose an application name to go to its page.Set page preferences (choose the settings icon).

 

 

변경 기록

Elastic Beanstalk 환경들에 대한 설정 정보들의 변경 기록 목록을 자세히 확인할 수 있다.

 

Change History
The Change history page shows a detailed list of configuration changes that have been made to your Elastic Beanstalk environments.
Things you can do on this page:
Filter displayed changes by text that you enter in the search bar.Load more events if the list is long.Keep your filtered results when you load more results, by leaving your filter text in place. Your filtered results append to the result set of the next page.

 

 

최근 환경 -> Spring-test-env1

이제 방금 구성하여 실행한 Spring-test-env1 환경의 대시보드를 구체적으로 살펴보자.

Environment Overview 대시보드는 다음과 같다. 현재 실행하고 있는 애플리케이션 버전의 AWS 리소스들을 확인할 수 있다.

 

Environment Overview
An environment is a collection of AWS resources running an application version. When you create an environment, Elastic Beanstalk provisions the resources needed to run the application version you specified.

The Overview page shows main environment details, and a list of recent events that the environment generated.

All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.

Things you can do on this page:

  • Get detailed cause information for an unhealthy status.
  • Upload and deploy application code.
  • Change the platform version that your instances run.

 

 

 

환경 구성

각 카테고리별로 그룹화된 각 환경 정보의 요약 화면은 다음과 같다.

소프트웨어, 인스턴스, 용량(가용 영역, 기간, 단위, 인스턴스 유형과 통계값 등), 로드 밸런서, 롤링 업데이트와 배포, 보안, 모니터링 등을 확인할 수 있다.

 

Environment Configuration
The Configuration overview page shows a summary of environment configuration option values, grouped by category.
All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.
Things you can do on this page:
Search for option names or values – Set Table View.See option values on category cards – Clear Table View.Edit options – Choose Edit in a category to edit options in it.

 

환경 로그 

설정한 환경에서 EC2 인스턴스로부터 얻은 로그들을 다운 받을 수 있다.

 

Environment Logs
The Logs page lets you retrieve and download logs from the Amazon EC2 instances in your environment.
All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.
Things you can do on this page:
Retrieve full logs or recent activity. The logs you retrieve are stored in Amazon S3, and this page lists them.Download logs that you retrieved. They are available for 15 minutes.

 

 

우린 여기서 오른쪽 상단의 로그 요청을 누른 후, 전체 로그에 대한 파일을 다운로드 받아보자.

 

다운로드 받은 로그 파일들 목록은 다음과 같다.

health deamon 파일부터 ngnix 프록시 서버와 관련된 로그들 등을 확인할 수 있다.

 

 

상태

상태(헬스) 페이지에서는 환경의 각 인스턴스에 대한 개선(확장)된 상태 정보들을 확인할 수 있다.

웹 앱의 HTTP 상태 코드별 응답 비율, 지연 시간, CPU 사용율 등을 확인할 수 있다.

 

Enhanced heatlh
The Health page shows live enhanced health information about every instance in your environment. Enhanced health monitoring lets Elastic Beanstalk closely monitor the resources in your environment so that it can assess the health of your application more accurately.
This information is available only when you enable enhanced health on your environment.
All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.
Things you can do on this page:
Filter displayed instances by health status.Reboot or terminate instances.

 

환경 모니터링 

모니터링 페이지에서는 환경의 상태와 관련된 계량, 통계 정보들을 확인할 수 있다. Elastic 로드 밸런싱과 Amazon EC2에 의해 제공되는 기본 계량 값들과 시간에 따른 환경 상태의 변화를 나타내는 그래프를 시각적으로 나타내고 있다.

 

Environment monitoring
The Monitoring page shows an overview of health-related metrics for your environment. This includes the default set of metrics provided by Elastic Load Balancing and Amazon EC2, and graphs that show how the environment's health has changed over time.
All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.
Things you can do on this page:
Configure the metrics and graphs that the page displays.Add alarms for supported metrics.

 

 

이벤트

이벤트 페이지에서는 EB 환경에서 발생한 이벤트 결과들의 스트림을 보여준다.

 

Event
The Events page shows the event stream for your environment. Elastic Beanstalk outputs event messages whenever you interact with the environment, and when any of your environment's resources are created or modified as a result.
All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.
Things you can do on this page:
Filter displayed events by minimal severity.Load more events if the list is long.

 

 

태그

태그 페이지에서는 EB 환경에 적용한 AWS 리소스와 관련한 태그들의 키-값을 보여준다. 

Tags
The Tags page shows the tags that you applied to your environment (and a few default ones). Tags are key-value pairs associated with AWS resources.
All environment pages include a navigation breadcrumb at the top, which you can use to return to the environment overview. A side navigation pane links to additional environment management pages and to the environment's web application.
Things you can do on this page:
Add tags.Edit or delete existing tags (except the default ones, which are read-only).

 

 


 

새로운 버전 업로드

 

기존의 코드에 변경 사항이 적용된 경우, 새로운 버전을 업로드 하기 위해서는 변경된 프로젝트 파일을 다시 Build하여 얻은 jar파일을 업로드 하여 배포하면 된다.

실행 버전 부분의 업로드 및 배포 를 클릭하자.

 

 

다시 새로운 jar 파일을 선택하고, 버전 레이블에 새로운 버전의 이름을 작성하자.

 

 

이제 애플리케이션 버전이 새로 업로드 된 것을 확인할 수 있다.

 

 

이렇게 새로운 버전이 업데이트 되면, 이전에 자바 내부 메모리를 이용하여 만들었던 회원 목록 데이터는 모두 사라진다.

그렇기 때문에 다음번에는 AWS RDS와 H2 DB를 연결하는 작업을 진행해 보려고 한다.

 

 

애플리케이션 환경 종료

 

배포를 중단하고, 구성했던 환경을 종료하고 싶은 경우 모든 환경 > 작업 선택 및 환경 종료를 클릭하면 된다.

 

 

환경 종료 확인 창이 뜨고, 연결된 리소스까지 모두 종료된다는 주의 문구가 나타난다.

마지막으로 확인 창에 종료할 환경의 이름을 잘 작성해주면 종료 버튼이 활성화된다.

 

 

종료 버튼까지 모두 누르면, Elastic Beanstalk가 해당 환경을 종료하게 된다. 

Auto Scaling Group Policy, 로드 밸런서 제거, EC2 인스턴스 삭제와 보안 그룹 제거 등등 여러 설정들을 하나하나 삭제해야 되기 때문에 생각보다 오랜 시간이 걸린다.

 

 

이제 모든 환경 정보를 다시 확인해보면,

위에서 만들었던 Springtest-env-1 환경이 안전하게 완전히, 종료 된 것을 확인할 수 있다.

 

 

 


[참고자료]

https://medium.com/javarevisited/deploy-spring-boot-app-to-aws-elastic-beanstalk-fa42b8b4bfa0

 

 

 

 

 

 

 

728x90
반응형
Comments