LoginSignup
4
7

More than 5 years have passed since last update.

[AWSCLI]VPC周りの簡易コマンドリファレンスその1

Last updated at Posted at 2015-07-09

結構長くなりそうなので複数回に分けます。
社内のお仕事でVPC作成スクリプト書くことになりました。それで調べたので、自分用リファレンスとしてまとめました。
ちなみに今回乗っけるのは今回使うつもりのものだけです。
--regionは必要に応じて使用

[AWSCLI]VPC周りの簡易コマンドリファレンスその2
[AWSCLI]VPC周りの簡易コマンドリファレンスその3


公式サイト
http://docs.aws.amazon.com/cli/latest/index.html
基本的にサンプルとかは公式から持ってきています。


aws ec2 create-vpc

オプション

オプション   意味     何を書けば良いか
--cidr-block CIDRを書きます 10.0.0.0/16とか
--instance-tenancy シングルテナントかどうか 値:default / dedicated

aws ec2 create-vpc --cidr-block 10.0.0.0/16

aws ec2 create-tags


オプション   意味     何を書けば良いか
--resources タグをつけたいサービスのid vpc-XXXXXXXX
サンプル
aws ec2 create-tags --resources vpc-XXXXXXXX --tags Key=Name,Value=hogehogeVPC

aws ec2 describe-vpc-attribute

attribute[名]:特性
describe[他・動]:~を描写する
まあ、VPCについてのいろんなものを出力してくれるくらいの認識で良いと思われる。


オプション   意味     何を書けば良いか
-vpc-id    vpcのid vpc-XXXXXXXX
--attribute enableDnsSupport 名前解決 false/true で設定されている
--attribute enableDnsHostnames DNS名 false/true で設定されている

describeは基本的に設定値の出力っぽいので何か書かなきゃいけないのはvpc-idくらいだと思われる。

enableDnsSupport は標準でtrue
enableDnsHostnames は標準でfalse

サンプル
aws ec2 describe-vpc-attribute --vpc-id vpc-XXXXXXXX --attribute xxxxxxxxxx

aws ec2 modify *****

modify[他・動]~を修正する
*に続く要素の値を修正するコマンドに続くのは以下の要素

modify-image-attribute
modify-instance-attribute
modify-network-interface-attribute
modify-reserved-instances
modify-snapshot-attribute
modify-subnet-attribute
modify-volume-attribute
modify-vpc-attribute
modify-vpc-endpoint

今回使用したのは

aws ec2 modify-vpc-attribute

オプション

オプション   意味     何を書けば良いか
-vpc-id    vpcのid vpc-XXXXXXXX
--attribute enableDnsSupport 名前解決 false/true で設定されている
--attribute enableDnsHostnames DNS名 false/true で設定されている

describeで確認した値を修正するには以下のようにします。


サンプル
aws ec2 modify-vpc-attribute --vpc-id vpc-XXXXXXXX --enable-dns-support "{\"Value\":false}"

aws ec2 modify-vpc-attribute --vpc-id vpc-XXXXXXXX --enable-dns-hostnames "{\"Value\":false}"

大事なのは末尾で設定したい値を書き込むこと。


結構よく使う&大事なポイント

--filters

describe系でフィルター処理をかけるオプション

--filters "Name=tag-key,Values=Owner"
--filters "Name=instance-type,Values=m1.small"

といった形で使われる。
nameにフィルター処理する要素名を入れて、valueにその設定値をいれる。

-output text

describe系で出力形式をテキストにして出力する。
これの何が大切かというとコマンドの前に変数を指定してあげれば変数に格納できる。
そのまま使おうとするといらんものまで取得するから「jq」による整形を適宜行う。

サンプル
aws ec2 describe-vpc-attribute --vpc-id vpc-XXXXXXXX --filters "Name=xxxx,Values=xxxx" -output text
サンプル(標準出力を変数に格納)
変数名=`aws ec2 describe-vpc-attribute --vpc-id vpc-XXXXXXXX --filters "Name=xxxx,Values=xxxx" -output text`
ほんとはJSONの処理をちゃんとしてから格納する

長くなってきたので今回はこの辺で。
次回は続きからでサブネットの作成やIGWの作成・アタッチなんかを見ていきます。

4
7
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
4
7