事前作業1.2. ルートテーブルの作成 (CloudShell: handson-cloud9-route-table)¶
手順の目的¶
ルートテーブル"handson-cloud9-route-table"を作成します。
設定値の指定¶
設定値の確認¶
各変数に正しい設定値が格納されていることを確認します。
変数の確認:
cat << END # 0. AWS_REGION:"ap-northeast-1" AWS_REGION="${AWS_REGION}" # 1. EC2_VPC_TAG_NAME:"handson-cloud9-vpc" EC2_VPC_TAG_NAME="${EC2_VPC_TAG_NAME}" # 2. EC2_ROUTE_TABLE_TAG_NAME:"handson-cloud9-route-table" EC2_ROUTE_TABLE_TAG_NAME="${EC2_ROUTE_TABLE_TAG_NAME}" END
下段の変数が入っていない、もしくは上段と同等の値が入っていない場合は、それぞれの手順番号に戻って変数の設定を行います。
処理の実行¶
VPC IDを取得します。
コマンド:
ec2_vpc_id=$( \ aws ec2 describe-vpcs \ --filters Name=tag:Name,Values=${EC2_VPC_TAG_NAME} \ --query 'Vpcs[].VpcId' \ --output text \ ) \ && echo ${ec2_vpc_id}結果(例):
vpc-xxxxxxxxxxxxxxxxx
タグ文字列を生成します。
変数の設定:
string_ec2_route_table_tag="ResourceType=route-table,Tags=[{Key=Name,Value=${EC2_ROUTE_TABLE_TAG_NAME}}]" \ && echo ${string_ec2_route_table_tag}結果(例):
ResourceType=route-table,Tags=[{Key=Name,Value=handson-cloud9-route-table}]
ルートテーブルを作成します。
変数の確認:
cat << END # ec2_vpc_id:"vpc-xxxxxxxxxxxxxxxxx" ec2_vpc_id="${ec2_vpc_id}" # string_ec2_route_table_tag:"ResourceType=route-table,Tags=[{Key=Name,Value=handson-cloud9-route-table}]" string_ec2_route_table_tag="${string_ec2_route_table_tag}" ENDコマンド:
aws ec2 create-route-table \ --vpc-id ${ec2_vpc_id} \ --tag-specifications ${string_ec2_route_table_tag}結果(例):
{ "RouteTable": { "Associations": [], "PropagatingVgws": [], "RouteTableId": "rtb-xxxxxxxxxxxxxxxxx", "VpcId": "vpc-xxxxxxxxxxxxxxxxx", "Tags": [ { "Key": "Name", "Value": "handson-cloud9-route-table" } ], "OwnerId": "XXXXXXXXXXXX", "Routes": [ { "GatewayId": "local", "DestinationCidrBlock": "10.0.0.0/16", "State": "active", "Origin": "CreateRouteTable" } ] } }
完了確認¶
「VPC"handson-cloud9-vpc"にルートテーブル"handson-cloud9-route-table"が存在する。」ことを確認します。
コマンド:
aws ec2 describe-route-tables \ --filters Name=vpc-id,Values=${ec2_vpc_id} \ Name=tag:Name,Values=${EC2_ROUTE_TABLE_TAG_NAME} \ --query "RouteTables[].Tags[?Key == \`Name\`].Value" \ --output text結果(例):
handson-cloud9-route-table
手順の完了¶
(参考) マネジメントコンソールの確認¶
VPCダッシュボード( https://console.aws.amazon.com/vpc/home )にアクセスします。
右上のリージョンメニューから"東京"を選択します。
左ペインの"ルートテーブル"をクリックします。
ルートテーブル一覧(画面)
検索欄にルートテーブル名"handson-cloud9-route-table"を入力して、エンターキーを押します。
ルートテーブル名"handson-cloud9-route-table"が表示されていることを確認します。