AWS Command Line Interfaceを使ってVPC環境を作ってみる
AWS Command Line Interfaceを使ってみたメモ。
試しにVPCの環境を作ってみます。
作ってみる
まずはVPC作成。
$ aws ec2 create-vpc --cidr-block 10.0.0.0/16 { "Vpc": { "InstanceTenancy": "default", "State": "pending", "VpcId": "vpc-9a19c9ff", "CidrBlock": "10.0.0.0/16", "DhcpOptionsId": "dopt-46a2b324" } }
次にsubnet。
$ aws ec2 create-subnet --vpc-id vpc-9a19c9ff --cidr-block 10.0.1.0/24 --availability-zone us-east-1a { "Subnet": { "VpcId": "vpc-9a19c9ff", "CidrBlock": "10.0.1.0/24", "State": "pending", "AvailabilityZone": "us-east-1a", "SubnetId": "subnet-2c675404", "AvailableIpAddressCount": 251 } } $ aws ec2 create-subnet --vpc-id vpc-9a19c9ff --cidr-block 10.0.2.0/24 --availability-zone us-east-1b { "Subnet": { "VpcId": "vpc-9a19c9ff", "CidrBlock": "10.0.2.0/24", "State": "pending", "AvailabilityZone": "us-east-1b", "SubnetId": "subnet-783ec80f", "AvailableIpAddressCount": 251 } }
Internet Gateway を作って、VPCにアタッチ。
$ aws ec2 create-internet-gateway { "InternetGateway": { "Tags": [], "InternetGatewayId": "igw-ff96699a", "Attachments": [] } } $ aws ec2 attach-internet-gateway --internet-gateway-id igw-ff96699a --vpc-id vpc-9a19c9ff { "return": "true" }
Route Table に Internet Gateway と subnet を追加。
$ aws ec2 create-route --route-table-id rtb-e9f2248c --destination-cidr-block 0.0.0.0/0 --gateway-id igw-ff96699a { "return": "true" } $ aws ec2 associate-route-table --subnet-id subnet-783ec80f --route-table-id rtb-e9f2248c { "AssociationId": "rtbassoc-f8449c9d" } $ aws ec2 associate-route-table --subnet-id subnet-2c675404 --route-table-id rtb-e9f2248c { "AssociationId": "rtbassoc-c2449ca7" }
結構楽です。
今日はこんなところで。