LoginSignup
2
4

More than 5 years have passed since last update.

AWS CLI で VPC のネットワーク環境構築するメモ

Posted at

こんな感じにしたい

VPC構成 (2).png

VPC を作成

aws ec2 create-vpc --cidr-block 10.0.0.0/16
aws ec2 create-tags --resources vpc-XXXXXXXX --tags Key=Name,Value=sample-vpc

gateway サブネット側設定

サブネット作成

aws ec2 create-subnet --vpc-id vpc-XXXXXXXX --cidr-block 10.0.0.0/24
aws ec2 create-tags --resources subnet-gwXXXXXX --tags Key=Name,Value=sample-vpc-gw

インターネットゲートウェイ作成 ~ VPC に紐付け

aws ec2 create-internet-gateway
aws ec2 create-tags --resources igw-XXXXXXXX --tags Key=Name,Value=sample-vpc-igw
aws ec2 attach-internet-gateway --vpc-id vpc-XXXXXXXX --internet-gateway-id igw-XXXXXXXX

ルートテーブル作成

aws ec2 create-route-table --vpc-id vpc-XXXXXXXX
aws ec2 create-tags --resources rtb-gwXXXXXX --tags Key=Name,Value=sample-vpc-gw-rtb
aws ec2 create-route --route-table-id rtb-gwXXXXXX --destination-cidr-block 0.0.0.0/0 --gateway-id igw-XXXXXXXX
aws ec2 associate-route-table --subnet-id subnet-gwXXXXXX --route-table-id rtb-gwXXXXXX

NATゲートウェイ作成

aws ec2 allocate-address --domain vpc
aws ec2 create-nat-gateway --subnet-id subnet-gwXXXXXX --allocation-id eipalloc-XXXXXXXX
aws ec2 create-tags --resources nat-XXXXXXXXXXXXXXXXX --tags Key=Name,Value=sample-vpc-nat-gw

サービス側サブネット作成

サブネット作成

aws ec2 create-subnet --vpc-id vpc-XXXXXXXX --cidr-block 10.255.1.0/24
aws ec2 create-tags --resources subnet-service1X --tags Key=Name,Value=sample-vpc-service1

ルートテーブル作成

aws ec2 create-route-table --vpc-id vpc-XXXXXXXX
aws ec2 create-tags --resources rtb-serviceXX --tags Key=Name,Value=sample-vpc-service1-rtb
aws ec2 create-route --route-table-id rtb-serviceXX --destination-cidr-block 0.0.0.0/0 --nat-gateway-id nat-XXXXXXXXXXXXXXXXX
aws ec2 associate-route-table --subnet-id subnet-service1X --route-table-id rtb-serviceXX
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4