2021년 10월 15일 금요일

aws ebextensions를 사용하여 eb 환경 설정.

eb의 환경을 변경해야 할 필요가 있을 경우, .ebextensions 폴더를 만들고 config 파일을 넣은 후 소스를 배포하면 eb의 환경을 변경할 수 있다.

https://docs.aws.amazon.com/ko_kr/elasticbeanstalk/latest/dg/ebextensions.html

기본적인 내용은 위의 내용을 참고하면 된다.

샘플들은 https://github.com/awsdocs/elastic-beanstalk-samples/tree/master/configuration-files 여기서 볼 수 있다.

이 문서는 https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/security-configuration/proxy-ratelimit-linux/nodejs/rate-limit-connections-nodejs.config 의 내용이다.

files 섹션에는 기본적으로 아래의 값이 들어간다.

files:
"/저장될 경로/파일명.확장자명":
mode: "권한(ex. 000644)"
owner: root
group: root
content: |
            위 파일에 기록될 내용


files:
"/tmp/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf":
owner: root
group: root
mode: "000644"
content: |

즉 위 내용은 /tmp/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf 이 파일을 만드는 것이다.(샵 문자는 그냥 파일 이름임.)

그리고 그 아래 부분을 보면 container_commands라는 부분이 있다. container_commands 는 웹서버가 설정되고 애플리케이션 버전 아카이브의 압축이 풀린 후에 실행된다고 한다.(https://mosei.tistory.com/entry/AWS-EBElastic-Beanstalk-ebextensions-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0)

container_commands:
99_move_config:
command: "mv -f /tmp/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf"

99_move_config를 수행하고 command는 파일을 이동시키는 것이다.(근데 files에서 생성한 파일을 옮기는건데...왜 이런 예제를 써놨는지는 모르겠음.)

container_commands:
99_move_config:
command: "mv -f /tmp/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf"
99_move_config_2:
command: "mv -f /tmp/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf"

위와 같이 files도 여러개의 파일을 생성할 수 있고, container_commands도 여러개의 명령을 수행할 수 있다.

추가로 container_commands 말고 commands도 있다.

commands는 웹서버가 설정되고 애플리케이션 버전이 추출되기 전에 실행되고,
container_commands 는 웹서버가 설정되고 애플리케이션 버전 아카이브의 압축이 풀린 후에 실행된다.
만약 chown 처럼 애플리케이션의 파일 소유자 권한 등을 세팅할 때에는 container_commands로 해야 한다.

댓글 없음: