EC2을 생성할 때 생성 및 사용되는 요소들에 대한 정의는 아래 링크에서 확인해주시기 바랍니다.
해당 글에는 각 요소에 대해서 자세히 설명하지 않을 예정입니다.
[AWS] EC2에 사용되는 기본 요소
VPC(Virtual Private Cloud)논리적으로 격리된 가상 네트워크에서 AWS 리소스를 할당할 수 있는 공간 → AWS의 확장 가능한 인프라를 사용한다는 이점과 함께 고객의 자체 데이터 센터에서 운영하는 기
tussle.tistory.com
AWS-CLI Setting.
Windows에서 AWS CLI 버전 1 설치, 업데이트 및 제거 - AWS Command Line Interface
이러한 구성 및 자격 증명 설정은 모든 AWS SDKs 및 에서 AWS CLI공유됩니다. 이 폴더를 제거하면 시스템에 남아 AWS SDKs 있는 사용자는 이 폴더에 액세스할 수 없습니다.
docs.aws.amazon.com
설치 결과
Configure설정
만드려는 목표.
AWS-CLI 명령어 예제
사용하는 Amazon EC2 예제 AWS CLI - AWS Command Line Interface
docs.aws.amazon.com
VPC 생성
aws ec2 create-vpc --cidr-block 10.2.0.0/16 --tag-specification "ResourceType=vpc, Tags=[{Key=Name, Value=cli-vpc}]" --output text
CIDR-Block = 10.2.0.0/16
Resource-Type = vpc
Tag = {Key = name, value = cli-vpc}
Subnet 생성
Public
Private
cli-vpc-id = 생성한 VPC-id
[public-subnet]
aws ec2 create-subnet --vpc-id {cli-vpc-id} --cidr-block 10.2.1.0/24 --availability-zone ap-northeast-2a --tag-specification "ResourceType=subnet, Tags=[{Key=Name, Value=cli-subnet-public}]"
[private-subnet]
aws ec2 create-subnet --vpc-id {cli-vpc-id} --cidr-block 10.2.2.0/24 --availability-zone ap-northeast-2a --tag-specification "ResourceType=subnet, Tags=[{Key=Name, Value=cli-subnet-private}]"
Route-Table 설정 및 연결
Route-Table 생성-[public, private]
aws ec2 create-route-table --vpc-id {vpc-id} --tag-specification "ResourceType=route-table, Tags=[{Key=Name, Value=cli-route-table-public}]"
aws ec2 create-route-table --vpc-id {vpc-id} --tag-specification "ResourceType=route-table, Tags=[{Key=Name, Value=cli-route-table-private}]"
Subnet 연결
aws ec2 associate-route-table --route-table-id {rtb-id} --subnet-id {subnet-id}
Internet Gateway 설정
Internet Gateway 생성
aws ec2 create-internet-gateway --tag-specification "ResourceType=internet-gateway, Tags=[{Key=Name, Value=cli-internet-gateway}]" --output text
Integer Gateway VPC 연결
aws ec2 attach-internet-gateway --vpc-id {vpc-id} --internet-gateway-id {igw-id}
Public Subnet 연결
aws ec2 create-route --route-table-id {rtb-id} --destination-cidr-block 0.0.0.0/0 --gateway-id {igw-id}
NAT Gateway 생성 및 연결
NAT Gateway 생성
aws ec2 create-nat-gateway --subnet-id {subnet-id} --allocation-id {elastic-ip-id} --tag-specification "ResourceType=natgateway, Tags=[{Key=Name, Value=cli-nat-gateway}]" --output text
Private Subnet 연결
aws ec2 create-route --route-table-id {rtb-id} --destination-cidr-block 0.0.0.0/0 --gateway-id {nat-id}
보안그룹 생성
보안 그룹 생성
aws ec2 create-security-group --group-name MySecurityGroup --description "My security group" --vpc-id {vpd-id}
Inbound설정 - Public
aws ec2 authorize-security-group-ingress --group-id {sg-id} --protocol {protocol} --port {port} --cidr {cidr, x.x.x.x/x}
Inbound설정 - Private
aws ec2 authorize-security-group-ingress --group-id {sg-id} --protocol {protocol} --port {port} --source-group {sg-group}
EC2 생성하기
Image 검색
aws ec2 describe-images --owners self amazon
EC2 생성
aws ec2 run-instances \\
--image-id {image-id} \\
--count {생성 개수} \\
--instance-type {인스턴스 타입} \\
--key-name {key-pair-name} \\
--security-group-ids {sg-id} \\
--subnet-id {subnet-id} \\
--associate-public-ip-address \\
--tag-specification "ResourceType=instance, Tags=[{Key=Name, Value=cli-public}]"
결과
VPC
Subnet
Route-Table
Internet Gateway
NAT Gateway
보안 그룹
EC2
SSH으로 접근하기
SSH Public EC2에 접근 → SSH Private EC2 접근
지금은 SSH로 접근을 하는 것이지만, 나중에 Public에서 WS을 이용해서 Private로 접근하도록 할 수 있습니다.
window Power Shell → chmod 400 <key>.pem
icacls.exe <key이름>.pem /reset
icacls.exe <key이름>.pem /grant:r "$($env:username):(r)"
icacls.exe <key이름>.pem /inheritance:r
ssh -i <key>.pem ubuntu@public-ip

Public EC2에 접근하였을 때 Private EC2로 SSH을 접근하려면 Public EC2에 <key>.pem 파일이 있어야 합니다.
그래서, Window에서 받은 .pem 파일을 sftp으로 public ec2에 전송해야 합니다.
- sftp 명령어 put을 이용해서 전달하기
- sftp, ftp을 지원해주는 “파일질라”사용하기
저는 2번을 이용해서 UI상으로 .pem 파일을 전송하였습니다.
파일질라 한글사이트
파일질라 무료 FTP 한글지원, 윈도우, 맥OS, 리눅스, 서버 FTP 다운로드 제공, 사용법, 자주묻는질문
www.filezilla.kr
파일 질라를 통해서 .pem 파일을 public Bastion Host 내부에 추가한 화면입니다.

Private EC2 SSH 접근
Public Bastion Host(EC2)을 통해서 Private Subnet에 존재하는 EC2로 SSH을 통해서 접근한 화면입니다.

'AWS' 카테고리의 다른 글
AWS EC2 생성(Console) (2) | 2024.09.17 |
---|---|
[AWS] EC2에 사용되는 기본 요소 (0) | 2024.08.22 |
[AWS] 같은 이메일로 프리 티어 여러 개 만들기 (0) | 2024.08.13 |
댓글