ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • AWS CLI를 이용한 EC2 생성
    공부합시다!/AWS 2024. 6. 5. 15:58
    728x90

    AWS CLI V2를 활용한 EC2 생성 과정 입니다.

    1. vpc 생성
    aws ec2 create-vpc --cidr-block 10.0.0.0/16
    
    2. subnet 생성
    aws ec2 create-subnet --vpc-id vpc-[ID] --cidr-block 10.0.0.0/24 --availability-zone ap-northeast-2a
    aws ec2 create-subnet --vpc-id vpc-[ID] --cidr-block 10.0.2.0/24 --availability-zone ap-northeast-2a
    aws ec2 create-subnet --vpc-id vpc-[ID] --cidr-block 10.0.4.0/24 --availability-zone ap-northeast-2a
    aws ec2 create-subnet --vpc-id vpc-[ID] --cidr-block 10.0.1.0/24 --availability-zone ap-northeast-2c
    aws ec2 create-subnet --vpc-id vpc-[ID] --cidr-block 10.0.3.0/24 --availability-zone ap-northeast-2c
    aws ec2 create-subnet --vpc-id vpc-[ID] --cidr-block 10.0.5.0/24 --availability-zone ap-northeast-2c
    
    3. Internet Gatway 생성
    aws ec2 create-internet-gateway
    aws ec2 attach-internet-gateway --internet-gateway-id igw-[ID] --vpc-id vpc-[ID]
    
    4. Route Table 생성 및 디폴트 스태틱 라우팅 생성
    aws ec2 create-route-table --vpc-id vpc-[ID]
    aws ec2 create-route --route-table-id rtb-[ID] --destination-cidr-block 0.0.0.0/0 --gateway-id igw-[ID]
    
    5. Subnet과 Routing Table 명시적 연결
    aws ec2 associate-route-table --subnet-id subnet-[ID] --route-table-id rtb-[ID]
    
     5.1. 해당 서브넷의 인스턴스에 public ip 자동 할당
    aws ec2 modify-subnet-attribute --subnet-id subnet-[ID] --map-public-ip-on-launch
    aws ec2 modify-subnet-attribute --subnet-id subnet-0882c4011ca79c1db --map-public-ip-on-launch
    aws ec2 modify-subnet-attribute --subnet-id subnet-0f0d2d4f6f1b87464 --map-public-ip-on-launch
    
    6. 보안 그룹 생성 및 프로토콜 및 port
    aws ec2 create-security-group --group-name "ssh-web" --description "ssh_web" --vpc-id vpc-[ID]
    aws ec2 authorize-security-group-ingress --group-id sg-[ID] --protocol tcp --port 22 --cidr 0.0.0.0/0
    aws ec2 authorize-security-group-ingress --group-id sg-[ID] --protocol tcp --port 80 --cidr 0.0.0.0/0
    
    7. Key Pair 생성
    aws ec2 create-key-pair --key-name sdkim_2 --query "KeyMaterial" --output text > sdkim_2.pem
    
    8. ec2 인스턴스 생성
    aws ec2 describe-images --owner self amazon			ami id 확인
    aws ec2 run-instances --image-id ami-[ID] --count 1 --instance-type t2.micro --key-name sdkim_2 --security-group-ids sg-[ID] --subnet-id subnet-[ID]
    aws ec2 describe-instances --instance-id i-[ID]
    
    ssh -i sdkim_2.pem ec2-user@IP주소

     

     

     

    728x90
Designed by Tistory.