よく使う「AWS Organizations」のAWS CLIチートシート
アカウント確認
最初にマスターアカウントかどうか確認する。本記事では 999999999999
をマスターアカウントとする。
$ aws sts get-caller-identity { "Account": "999999999999", "UserId": "AIDAIBIY7OM4E3EXAMPLE", "Arn": "arn:aws:iam::999999999999:user/GiornoGiovanna" }
Organizationの確認
Organizationリソースが作られていることを確認。Organizationが存在しない場合、エラーになる。
$ aws organizations describe-organization { "Organization": { "AvailablePolicyTypes": [ { "Status": "ENABLED", "Type": "SERVICE_CONTROL_POLICY" } ], "MasterAccountId": "999999999999", "MasterAccountArn": "arn:aws:organizations::999999999999:account/o-lt1example/999999999999", "FeatureSet": "ALL", "MasterAccountEmail": "aws+master@example.com", "Id": "o-lt1example", "Arn": "arn:aws:organizations::999999999999:organization/o-lt1example" } }
Rootの確認
Organizational UnitのParent IDとして、RootのIDが必要になるので確認する。この例だとr-exa9
がRootのIDである。
$ aws organizations list-roots { "Roots": [ { "PolicyTypes": [ { "Status": "ENABLED", "Type": "SERVICE_CONTROL_POLICY" } ], "Id": "r-exa9", "Arn": "arn:aws:organizations::999999999999:root/o-lt1example/r-exa9", "Name": "Root" } ] }
Organizational Unit(OU)の一覧確認
この例では、service
とsandbox
という二つのOUが定義されている。
$ aws organizations list-organizational-units-for-parent --parent-id r-exa9 { "OrganizationalUnits": [ { "Id": "ou-exa9-n2awypd1", "Arn": "arn:aws:organizations::999999999999:ou/o-lt1example/ou-exa9-n2awypd1", "Name": "sandbox" }, { "Id": "ou-exa9-8huwo2x2", "Arn": "arn:aws:organizations::999999999999:ou/o-lt1example/ou-exa9-8huwo2x2", "Name": "service" } ] }
Organizational Unit(OU)の作成
ここでは admin
というOUを作成している。
$ aws organizations create-organizational-unit --parent-id r-exa9 --name admin { "OrganizationalUnit": { "Id": "ou-exa9-m8b3wkn0", "Arn": "arn:aws:organizations::999999999999:ou/o-lt1example/ou-exa9-m8b3wkn0", "Name": "admin" } }
アカウントの一覧
マスターアカウントしかないので一件しか表示されないが、AWSアカウントを追加していくと、どんどん増えていく。
$ aws organizations list-accounts { "Accounts": [ { "Status": "ACTIVE", "Name": "Master Account", "Email": "aws+master@example.com", "JoinedMethod": "INVITED", "JoinedTimestamp": 1522716559.815, "Id": "999999999999", "Arn": "arn:aws:organizations::999999999999:account/o-lt1example/999999999999" } ] }
アカウントの作成
このコマンドが最も重要。AWS Organizationsでは頻繁に使うことになる。
$ aws organizations create-account --iam-user-access-to-billing ALLOW --account-name "Test Account" --email "aws+test@example.com" { "CreateAccountStatus": { "RequestedTimestamp": 1526351856.208, "State": "IN_PROGRESS", "Id": "car-6061057e811e8b031500c1234abcd", "AccountName": "Test Account" } }
アカウントステータスの参照
create-accountコマンドでは、アカウントIDが分からないので、このコマンドでアカウントIDを確認する。
$ aws organizations describe-create-account-status --create-account-request-id car-6061057e811e8b031500c1234abcd { "CreateAccountStatus": { "AccountName": "Test Account", "State": "SUCCEEDED", "RequestedTimestamp": 1526351856.401, "CompletedTimestamp": 1526351860.693, "Id": "car-6061057e811e8b031500c1234abcd", "AccountId": "123456789012" } }
アカウントの参照
アカウントの詳細情報がこれで確認できる。
$ aws organizations describe-account --account-id 123456789012 { "Account": { "Status": "ACTIVE", "Name": "Test Account", "Email": "aws+test@example.com", "JoinedMethod": "CREATED", "JoinedTimestamp": 1526351858.576, "Id": "123456789012", "Arn": "arn:aws:organizations::999999999999:account/o-lt1example/123456789012" } }
指定したOrganizational Unit(OU)にアカウントを移動
このコマンドはレスポンスがないのが正常。
$ aws organizations move-account --account-id 123456789012 --source-parent-id r-exa9 --destination-parent-id ou-exa9-m8b3wkn0
アカウントの親Organizational Unit(OU)の参照
正しくOUが設定できたかどうか確認する。
$ aws organizations list-parents --child-id 123456789012 { "Parents": [ { "Type": "ORGANIZATIONAL_UNIT", "Id": "ou-exa9-m8b3wkn0" } ] }
リージョン指定
2018年10月現在、公式ドキュメントでは、us-east-1
を指定するよう注意書きがある。
Use the following parameter with each command to specify the endpoint: --region us-east-1
しかし、この情報は正しくなく、現在はリージョン指定がなくてもコマンドの実行は可能である。
AWS のリージョンとエンドポイントにはシレッと、どのリージョンからアクセスしても、エンドポイントorganizations.us-east-1.amazonaws.com
にアクセスすることが明記されている。
まとめ
AWS Organizationsの普段の運用であれば、これぐらいあれば事足りる。