Last active
March 23, 2019 06:41
-
-
Save code-machina/291b14ed4c6f895f87dec8052d959e45 to your computer and use it in GitHub Desktop.
AWS CLI command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AWS 인스턴스를 실행 | |
aws ec2 run-instances --instance-type [인스턴스 타입을 입력, t2.micro] --image-id [AMI 아이디를 입력, 인스턴스 정보] --count [생성할 인스턴스 수를 입력, 숫자] | |
# Topic : Create Custom AMI | |
## 권한 상승 | |
sudo su | |
## 업데이트 | |
yum update -y | |
## 아파치 웹서버 설치 | |
yum install -y httpd | |
## 서비스 시작 | |
systemctl start httpd | |
systemctl enable httpd | |
## Simple HTML Page for checking wether or not there are web service. | |
echo "Hello world" > /var/www/html/index.html | |
## 접근 확인 | |
curl localhost:80 | |
# Topic : Monitoring Scripts | |
## Perl 패키지 설치 | |
sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64 | |
## Monitoring Script 다운로드 | |
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O | |
## 압축 해제 | |
unzip CloudWatchMonitoringScripts-1.2.2.zip && \ | |
rm CloudWatchMonitoringScripts-1.2.2.zip && \ | |
cd aws-scripts-mon | |
## IAM 에 권한을 추가 | |
### 서비스 > IAM > 역할 > 생성 > CloudWatchFullAccess 선택 > 이름 지정 생성 | |
CloudWatchFullAccess | |
### 인스턴스 우클릭 > 인스턴스 설정 > IAM 역할 연결/바꾸기 클릭 > 생성한 권한 할당 | |
## 스크립트 실행 | |
./mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --mem-used --mem-avail | |
## 정상 실행 메시지 확인하기 | |
> Successfully reported metrics to CloudWatch. | |
## 크론에 추가 (5분 마다 스크립트 실행하기) | |
crontab -e | |
> */5 * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron | |
# Topic: CloudWatch logs for EC2 | |
## awslogs 설치 | |
sudo yum install -y awslogs | |
## cli 설정 변경 | |
vim /etc/awslogs/awscli.conf | |
> region 편집 | |
[plugins] | |
cwlogs = cwlogs | |
[default] | |
region = us-east-1 | |
## awslogs 서비스 시작하기 (Amazon Linux 2) | |
sudo systemctl start awslogsd | |
sudo systemctl enable awslogsd.service | |
## 미국 버지니아 북부로 리전을 재지정하여 CloudWatch 의 로그를 확인 | |
/var/log/messages 가 생성되어 있음을 확인 | |
# Topic : Access to Parameter Store | |
aws ssm get-parameters --names /my-app/dev/db-url /my-app/dev/db-password | |
aws ssm get-parameters --names /my-app/dev/db-url /my-app/dev/db-password --with-decryption | |
aws ssm get-parameters-by-path --path /my-app/dev | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment