AWS Elastic Beanstalk란?
- AWS Elastic Beanstalk는 Java, .NET, PHP, Node.js, Python, Ruby, Go, Docker를 사용하여 Apache, Nginx, Passenger, IIS와 같은 친숙한 서버에서 개발된 웹 애플리케이션 및 서비스를 간편하게 배포하고 조정할 수 있는 서비스입니다.
- Elastic Beanstalk를 사용하면 코드를 업로드해서 용량 프로비저닝, 로드 밸런싱, 오토 스케일링, 애플리케이션 상태 모니터링, 배포를 자동으로 처리하도록 구성할 수 있습니다. 배포 완료 후 애플리케이션을 실행하는 데 필요한 AWS 리소스를 쉽게 제어할 수 있으며 언제든지 기본 리소스에 액세스할 수 있습니다.
사용법
1. Install the CLI
2. Project 만들기 및 기본적인 구성
# mkdir HelloWorld
# cd HelloWorld
# eb init --profile aws-devops
여기서 프로젝트 관련하여 옵션들을 물어봅니다.
https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/eb-cli3-configuration.html
EB CLI 구성 - AWS Elastic Beanstalk
Windows에서 .ebignore 파일을 추가하면 EB CLI가 심볼 링크를 따라가서 소스 번들을 만들 때 연결된 파일을 포함시킵니다. 이는 알려진 문제로 향후 업데이트에서 수정될 예정입니다.
docs.aws.amazon.com
# echo "Hello World" > index.html
# eb create dev-env
여기서 어플리케이션 구동을 위한 새로운 환경을 정의합니다.
https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/eb3-create.html
eb create - AWS Elastic Beanstalk
단일 인스턴스 환경은 프로덕션을 지원하지 않습니다. 배포 중에 인스턴스가 불안정하게 되거나, Elastic Beanstalk가 구성 업데이트 중 인스턴스를 종료했다가 다시 시작하는 경우 일정 시간 동안
docs.aws.amazon.com
# eb open
어플리케이션을 URL방식으로 접근할수 있게 합니다.(ELB 적용)
3. EB CLI를 사용하여 환경 관리 Doc
https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/eb-cli3-getting-started.html
EB CLI를 사용하여 Elastic Beanstalk 환경 관리 - AWS Elastic Beanstalk
프로젝트 폴더의 git 리포지토리를 초기화한 경우, 대기 중인 변경 사항이 있더라도 EB CLI가 항상 최신 커밋을 배포합니다. eb deploy를 실행하기 전에 변경 사항을 커밋하여 이를 환경에 배포합니
docs.aws.amazon.com
4. 생성한 환경을 백업하여 재사용하기
# eb config save dev-env --cfg initial-configuration
현재 환경 설정값을 .elasticbeanstalk/saved_configs/ 경로에 'initial-configuration'이라는 이름의 yml 파일로 저장하기
# eb setenv ENABLE_COOL_NEW_FEATURE=true
현재 작업중인 환경 중 일부분 만 변경하기
# eb config save dev-env --cfg prod
위에서 수정한 버전의 버전을 .elasticbeanstalk/saved_configs/ 경로에 'prod'라는 이름의 yml 파일로 저장
# eb config dev-env --cfg prod
dev-env 어플리케이션의 환경을 'prod' 프로필 구성으로 변경하여 적용
ElasticBeansTalks의 RDS관련
ElasticBeansTalk로 RDS를 생성하게 되면 동일 CloudFormation Stack으로 생성되기 때문에 생명주기가 어플리케이션과 묶여있게 된다. Production 환경이라면 분리하여 RDS를 운영하기를 권장한다.
데이터베이스를 Elastic Beanstalk 환경에서 분리하여 유연성이 뛰어난 구성으로 이동할 수 있습니다. 분리된 데이터베이스는 외부 Amazon RDS 데이터베이스 인스턴스로 계속 작동할 수 있습니다. 환경의 상태는 데이터베이스를 분리해도 영향을 받지 않습니다. 환경을 종료해야 하는 경우 환경을 종료할 수 있으며 Elastic Beanstalk 외부에서 데이터베이스를 사용 가능하고 작동하도록 유지하는 옵션을 선택할 수도 있습니다.
외부 데이터베이스를 사용하면 몇 가지 장점이 있습니다. 여러 환경에서 외부 데이터베이스에 연결하고, 통합 데이터베이스에서 지원되지 않는 데이터베이스 유형을 사용하고, 블루/그린 배포를 수행할 수 있습니다. Elastic Beanstalk가 생성한 분리된 데이터베이스를 사용하는 대신 Elastic Beanstalk 환경 외부에서 데이터베이스 인스턴스를 생성할 수도 있습니다.
Extension for Resource, Command&Container Command, configs
모든 구성 파일을 소스 번들 루트의 .ebextensions라는 단일 폴더에 저장한다.
예시
.ebextensions/autoscaling.config
option_settings:
# See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalingasg
aws:autoscaling:asg:
MinSize: 1
MaxSize: 10
Cooldown: 240
# See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalinglaunchconfiguration
aws:autoscaling:launchconfiguration:
InstanceType: t2.micro
# ImageId: ...
# SecurityGroups: ...
# InstanceIamProfile: ....
# This format works too:
# option_settings:
# - namespace: namespace
# option_name: option name
# value: option value
관련문서
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions-optionsettings.html
Option settings - AWS Elastic Beanstalk
Option settings You can use the option_settings key to modify the Elastic Beanstalk configuration and define variables that can be retrieved from your application using environment variables. Some namespaces allow you to extend the number of parameters, an
docs.aws.amazon.com
예시
.ebextensions/dynamodb.config
Resources:
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
KeySchema:
HashKeyElement:
AttributeName: id
AttributeType: S
# create a table with the least available rd and wr throughput
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
NotificationTopic:
Type: AWS::SNS::Topic
Outputs:
NotificationTopicArn:
Description: Notification topic ARN
Value: { "Ref" : "NotificationTopic" }
option_settings:
aws:elasticbeanstalk:application:environment:
# these are assigned dynamically during a deployment
NOTIFICATION_TOPIC: '`{"Ref" : "NotificationTopic"}`'
DYNAMODB_TABLE: '`{"Ref" : "DynamoDBTable"}`'
AWS_REGION: '`{"Ref" : "AWS::Region"}`'
# ssh onto the instance and run:
# /opt/elasticbeanstalk/bin/get-config environment
# /opt/elasticbeanstalk/bin/get-config environment -k NOTIFICATION_TOPIC
# /opt/elasticbeanstalk/bin/get-config environment -k DYNAMODB_TABLE
# /opt/elasticbeanstalk/bin/get-config optionsettings
예시
.ebextensions/container-commands.config
# Commands
# You can use the commands key to execute commands on the EC2 instance. The commands run before the application and web server are set up and the application version file is extracted.
commands:
create_hello_world_file:
command: touch hello-world.txt
cwd: /home/ec2-user
# Container Commands
# You can use the container_commands key to execute commands that affect your application source code. Container commands run after the application and web server have been set up and the application version archive has been extracted, but before the application version is deployed.
container_commands:
modify_index_html:
command: 'echo " - modified content" >> index.html'
database_migration:
command: 'echo "do a database migration"'
# You can use leader_only to only run the command on a single instance
leader_only: true
관련문서
command : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-commands
Customizing software on Linux servers - AWS Elastic Beanstalk
Elastic Beanstalk supports two underlying package managers for Python, pip and easy_install. However, in the syntax of the configuration file, you must specify the package manager name as python. When you use a configuration file to specify a Python packag
docs.aws.amazon.com
※ command는 EC2에서 어플리케이션과 웹서버가 Setup되기 전에 수행된다.
container-command : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-container-commands
Customizing software on Linux servers - AWS Elastic Beanstalk
Elastic Beanstalk supports two underlying package managers for Python, pip and easy_install. However, in the syntax of the configuration file, you must specify the package manager name as python. When you use a configuration file to specify a Python packag
docs.aws.amazon.com
※ container-command는 어플리케이션과 웹서버가 Setup된 후에 실행된다. 그래서 어플리케이션 소스를 Modify해서 어플리케이션에 적용할 수 있다.
'IaaS > 퍼블릭클라우드' 카테고리의 다른 글
(AWS) Lambda 에 대해서 (0) | 2022.02.07 |
---|---|
(AWS) Elastic Beanstalk의 CI/CD에 대해서 (0) | 2022.02.07 |
(AWS) CloudFormation Stack Policy란? (0) | 2022.02.06 |
(AWS) cfn-signal, cfn-get-metadata, cfn-hup 이란? (0) | 2022.02.06 |
(AWS) CloudFormation Drift Detection, Status Code란? (0) | 2022.01.28 |