1. ๋ชฉ์
๐ก
์๋ฒ ์ด์์ค auto-scaling์ผ๋ก scale-out์ด ๋ ์ ๋ชจ๋ ์๋ฒ๊ฐ ํ์ด์ง ์
๋ฐ์ดํธ ๋๋์ง ํ์ธ๊ณผ์ ์ ๊ฑฐ์ณ ๋ณด์ ์๋ฅผ ๋ค์ด) ํํ์ด์ง์ ์ด๋ฒคํธ ๊ธฐ๊ฐ์ ์ฆ๊ฐ์ ์ธ ์
๋ฐ์ดํธ๋ฅผ ํด์ฃผ๊ธฐ ์ํด sacle-out ๋ ๋๋ง๋ค EFS ๋ฅผ ํตํด ๋ชจ๋ ์๋ฒ์ ํ์ด์ง๋ฅผ ์
๋ฐ์ดํธ ํด๋ณด์
2.๊ตฌ์ฑ
ec2 ์์ฑ
EFS ์์ฑ
๊ฐ๋ ์ฐธ๊ณ : https://practice.hooniworld.io/entry/AWS-EFS-๊ฐ๋ -๋ฐ-๊ตฌ์ฑ-๋ฐฉ๋ฒ
EFS ์ฌ์ฉ ์์
- EFS ์์ฑ์ VPC ์์ AZ subnet๋น mount targer์์ฑ
- ๋๊ฐ ์ด์์ผ ๊ฒฝ์ฐ ํ๊ฐ๋ง mount target ์์ฑ ๊ฐ๋ฅ
ec2-EFS ๋ง์ดํธ
- nfs ํด๋ผ์ด์ธํธ ์ค์น
sudo yum -y update $ sudo reboot sudo yum -y install nfs-utils
efs ํ์ผ ์์ฑํ AMI ์์ฑ
auto sacling ์์ฑ
3. ํ ์คํธ
cloudwatch ์ด๋ฒคํธ - run command ๋์
lambda ์ด์ฉํ - run command
- ๋๋ค ์ญํ ์์ฑ → ์ฌ์ฉํ ์๋น์ค๋ค์ ๋ํด์ ์ญํ ์ ์ง์ ํด์ฃผ์๋ค.
- ์ฝ๋ ์์ฑ
1. ๋จ์ผ ์ธ์คํด์ค run command ๋์ import json import boto3 def lambda_handler(event, context): ssm_client = boto3.client('ssm') response = ssm_client.send_command( InstanceIds=['i-0e4c2788a45b4baf2'], DocumentName="AWS-RunShellScript", Parameters={'commands': ['sudo echo "<html><body>lambda test webserver6</body></html>" > /var/www/html/index.html']}, ) return { 'statusCode': 200 } 2. tag๋ฅผ ์ด์ฉํ run command ๋์ import json import boto3 ssm = boto3.client('ssm') def lambda_handler(event, context): ssmcommand = ssm.send_command( Targets = [ {'Key': 'tag:Name', 'Values': [ 'ec2-efs'] } ], DocumentName="AWS-RunShellScript", Parameters={'commands': ['sudo cp -fv "<html><body>tag lambda runcommand22</body></html>" > /efstest/index.html'],['sudo cp -fv /efstest/index.html /var/www/html/] }, ) return{ 'status_code': 200 }
๊ฒฐ๋ก
๋ฐ๋ผ์, Cloudwatch๋ฅผ ์ด์ฉํ์ฌ SSM runcommand ๋ฅผ ์ ์ฉํ๊ธฐ๋ณด๋จ Cloudwatch Event ์ Lambda๋ฅผ ํธ๋ฆฌ๊ฑฐ ์ํค๋ ๋ฐฉ์์ด ์ฉ์ดํ๋ค,
๋ํ, ASG ๊ตฌ์ฑ ๋ฐฉ์์ค Launch Template์ ์ด์ฉํ์ฌ ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ํตํ์ฌ ์๋ฒ๋ฅผ ์ ๋ฐ์ดํธ ํ๋ ๋ฐฉ์์ด ์กด์ฌ ํ๋ฉฐ
ํด๋น Template์ ์ธ์คํด์ค ์๋ก๊ณ ์นจ or Warm pool ๋ฐฉ์์ ์ ์ฉํ๋ฉด ํธ๋ฆฌํ ๊ฒ ์ด๋ค.
'Automation' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
SSM Automation์ ํตํ ์๋ํ (0) | 2022.08.23 |
---|---|
image builder 2 (0) | 2021.06.16 |
Image Builder -golden ami ์์ฑ (0) | 2021.03.29 |
Lambda Ec2 start / stop Tag๊ธฐ๋ฐ (0) | 2021.01.20 |