사전 요구사항
1. 콘솔용 EC2 생성
VPC 생성
aws ec2 create-vpc --cidr-block 100.100.0.0/16 --tag-specifications "ResourceType=vpc,Tags=[{Key=Service,Value=DEV},{Key=Name,Value=KB-VPC}]"
서브넷 생성
aws ec2 create-subnet --vpc-id vpc-03140520781c88fdd --cidr-block 100.100.1.0/24 --availability-zone ap-northeast-2a --tag-specifications "ResourceType=subnet,Tags=[{Key=Service,Value=DEV},{Key=Name,Value=DEV-Public-Subnet-a}]"
서브넷 퍼플릭IP 자동할당
aws ec2 modify-subnet-attribute --subnet-id subnet-09dee03a175a68fd2 --map-public-ip-on-launch
인터넷GW 생성
aws ec2 create-internet-gateway --tag-specifications "ResourceType=internet-gateway,Tags=[{Key=Service,Value=DEV},{Key=Name,Value=DEV-IGW}]"
IGW 연결
aws ec2 attach-internet-gateway --vpc-id vpc-0de527d9f64877014 --internet-gateway-id igw-0cb59f511d334897d
기본 라우팅테이블 조회
aws ec2 describe-route-tables --filter "Name=vpc-id,Values=vpc-0de527d9f64877014"
기본 라우팅테이블 IGW 연결
aws ec2 create-route --route-table-id rtb-06ce8ce99bdeed3e9 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-0cb59f511d334897d
기본라우팅테이블 서브넷 연결
aws ec2 associate-route-table --subnet-id subnet-09dee03a175a68fd2 --route-table-id rtb-06ce8ce99bdeed3e9
KeyPair 생성
aws ec2 create-key-pair --key-name DEV-KB-KeyPair --query "KeyMaterial" --output text > DEV-KB-KeyPair.pem
aws ec2 describe-key-pairs --key-name DEV-KB-KeyPair
SG생성
aws ec2 create-security-group --group-name DEV-Public-SG --description "Security group for SSH access" --vpc-id vpc-0de527d9f64877014 --tag-specifications "ResourceType=security-group,Tags=[{Key=Service,Value=DEV},{Key=Name,Value=DEV-Public-SG}]"
SG SSH 정책 추가
aws ec2 authorize-security-group-ingress --group-id sg-05aa9e09455d719cf --protocol tcp --port 22 --cidr 0.0.0.0/0
EC2 생성
aws ec2 run-instances --image-id ami-0a0de518b1fc4524c --count 1 --instance-type t2.micro --key-name DEV-KB-KeyPair --security-group-ids sg-05aa9e09455d719cf --subnet-id subnet-09dee03a175a68fd2 --tag-specifications "ResourceType=instance,Tags=[{Key=Service,Value=DEV},{Key=Name,Value=EC2-CONSOLE}]"
EC2 공인IP 확인
aws ec2 describe-instances --filter "Name=tag:Name,Values=EC2-CONSOLE"
또는
aws ec2 describe-instances --instance-ids i-0c7cedd469c58ebee"
EC2 접속 확인
ssh ec2-user@3.36.123.26
축하합니다!
Amazone Linux 설치가 완료되었습니다.