Organizationsアカウント"handson-cli-organizations-account"を作成します。
手順に必要な設定値を変数に格納をします。
1. AWSアカウント名
AWSアカウント名を指定します。
変数の設定: ORGANIZATIONS_ACCOUNT_NAME="handson-cli-organizations-account"
変数の設定:
ORGANIZATIONS_ACCOUNT_NAME="handson-cli-organizations-account"
2. メールアドレス
一時ファイルを指定します。
変数の設定: DIR_TMP="${HOME}/tmp-handson-cli-organizations" 変数の設定: FILE_TMP="${DIR_TMP}/mail_address.tmp" \ && echo ${FILE_TMP} 結果(例): ${HOME}/tmp-handson-cli-organizations/mail_address.tmp
DIR_TMP="${HOME}/tmp-handson-cli-organizations"
FILE_TMP="${DIR_TMP}/mail_address.tmp" \ && echo ${FILE_TMP}
結果(例):
${HOME}/tmp-handson-cli-organizations/mail_address.tmp
一時ファイルをsourceコマンドで読み込みます。
コマンド: source ${FILE_TMP} 結果(例): (出力なし)
コマンド:
source ${FILE_TMP}
(出力なし)
メールアドレスを確認します。
コマンド: echo "${MAIL_ADDRESS}" 結果(例): <事前に用意したメールアドレス>
echo "${MAIL_ADDRESS}"
<事前に用意したメールアドレス>
3. 一時ファイルの指定
一時ファイル用ディレクトリを指定します。
変数の設定: DIR_TMP="${HOME}/tmp-handson-cli-organizations"
ディレクトリが存在することを確認し、存在しない場合は作成します。
コマンド: ls -d ${DIR_TMP} > /dev/null 2>&1 \ || mkdir -p ${DIR_TMP}
ls -d ${DIR_TMP} > /dev/null 2>&1 \ || mkdir -p ${DIR_TMP}
出力ファイル名を指定します。
変数の設定: FILE_ORGANIZATIONS_ACCOUNT_OUTPUT="${DIR_TMP}/${ORGANIZATIONS_ACCOUNT_NAME}-output.json" \ && echo ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT} 結果(例): ${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-account-output.json
FILE_ORGANIZATIONS_ACCOUNT_OUTPUT="${DIR_TMP}/${ORGANIZATIONS_ACCOUNT_NAME}-output.json" \ && echo ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT}
${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-account-output.json
各変数に正しい設定値が格納されていることを確認します。
変数の確認: cat << END # 1. ORGANIZATIONS_ACCOUNT_NAME:"handson-cli-organizations-account" ORGANIZATIONS_ACCOUNT_NAME="${ORGANIZATIONS_ACCOUNT_NAME}" # 2. MAIL_ADDRESS:"<事前に用意したメールアドレス>" MAIL_ADDRESS="${MAIL_ADDRESS}" # 3. FILE_ORGANIZATIONS_ACCOUNT_OUTPUT:"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-account-output.json" FILE_ORGANIZATIONS_ACCOUNT_OUTPUT="${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT}" END
変数の確認:
cat << END # 1. ORGANIZATIONS_ACCOUNT_NAME:"handson-cli-organizations-account" ORGANIZATIONS_ACCOUNT_NAME="${ORGANIZATIONS_ACCOUNT_NAME}" # 2. MAIL_ADDRESS:"<事前に用意したメールアドレス>" MAIL_ADDRESS="${MAIL_ADDRESS}" # 3. FILE_ORGANIZATIONS_ACCOUNT_OUTPUT:"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-account-output.json" FILE_ORGANIZATIONS_ACCOUNT_OUTPUT="${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT}" END
各変数について、上の行と下の行の値の内容もしくは形式が同じであることを確認します。 もし異なる場合は、それぞれの手順番号に戻って変数の設定を行います。
AWSアカウントを作成します。
変数の確認: cat << END # ORGANIZATIONS_ACCOUNT_NAME:"handson-cli-organizations-account" ORGANIZATIONS_ACCOUNT_NAME="${ORGANIZATIONS_ACCOUNT_NAME}" # MAIL_ADDRESS:"<事前に用意したメールアドレス>" MAIL_ADDRESS="${MAIL_ADDRESS}" # FILE_ORGANIZATIONS_ACCOUNT_OUTPUT:"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-account-output.json" FILE_ORGANIZATIONS_ACCOUNT_OUTPUT="${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT}" END コマンド: aws organizations create-account \ --account-name ${ORGANIZATIONS_ACCOUNT_NAME} \ --email ${MAIL_ADDRESS} \ --iam-user-access-to-billing ALLOW \ > ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT} cat ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT} 結果(例): { "CreateAccountStatus": { "Id": "car-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "AccountName": "handson-cli-organizations-account", "State": "IN_PROGRESS", "RequestedTimestamp": "2023-12-07T01:23:45.678000+00:00" } }
cat << END # ORGANIZATIONS_ACCOUNT_NAME:"handson-cli-organizations-account" ORGANIZATIONS_ACCOUNT_NAME="${ORGANIZATIONS_ACCOUNT_NAME}" # MAIL_ADDRESS:"<事前に用意したメールアドレス>" MAIL_ADDRESS="${MAIL_ADDRESS}" # FILE_ORGANIZATIONS_ACCOUNT_OUTPUT:"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-account-output.json" FILE_ORGANIZATIONS_ACCOUNT_OUTPUT="${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT}" END
aws organizations create-account \ --account-name ${ORGANIZATIONS_ACCOUNT_NAME} \ --email ${MAIL_ADDRESS} \ --iam-user-access-to-billing ALLOW \ > ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT} cat ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT}
{ "CreateAccountStatus": { "Id": "car-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "AccountName": "handson-cli-organizations-account", "State": "IN_PROGRESS", "RequestedTimestamp": "2023-12-07T01:23:45.678000+00:00" } }
アカウント作成リクエストIDを取得します。
コマンド: AWS_CREATE_ACCOUNT_REQUEST_ID=$( \ cat ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT} \ | jp.py 'CreateAccountStatus.Id' \ | sed 's/\"//g' \ ) \ && echo ${AWS_CREATE_ACCOUNT_REQUEST_ID} 結果(例): car-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AWS_CREATE_ACCOUNT_REQUEST_ID=$( \ cat ${FILE_ORGANIZATIONS_ACCOUNT_OUTPUT} \ | jp.py 'CreateAccountStatus.Id' \ | sed 's/\"//g' \ ) \ && echo ${AWS_CREATE_ACCOUNT_REQUEST_ID}
car-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
「AWSアカウント"handson-cli-organizations-account"が存在する。」ことを確認します。
コマンド: aws organizations list-accounts \ --query "Accounts[?Name == \`${ORGANIZATIONS_ACCOUNT_NAME}\`].Name" \ --output text 結果(例): handson-cli-organizations-account
aws organizations list-accounts \ --query "Accounts[?Name == \`${ORGANIZATIONS_ACCOUNT_NAME}\`].Name" \ --output text
handson-cli-organizations-account
「AWSアカウント"handson-cli-organizations-account"の作成が成功している。」ことを確認します。
コマンド: aws organizations describe-create-account-status \ --create-account-request-id ${AWS_CREATE_ACCOUNT_REQUEST_ID} \ --query 'CreateAccountStatus.State' \ --output text 結果(例): SUCCEEDED
aws organizations describe-create-account-status \ --create-account-request-id ${AWS_CREATE_ACCOUNT_REQUEST_ID} \ --query 'CreateAccountStatus.State' \ --output text
SUCCEEDED
Organizationsダッシュボード( https://console.aws.amazon.com/organizations/v2/home/accounts)にアクセスします。
左ペインの"AWSアカウント"をクリックします。
AWSアカウント(画面)
組織が存在することを確認します。
課題
動作確認