ハンズオン(簡易版): Organizations基礎(アカウント招待)

6.8 [招待アカウントroot]. OrganizationsアカウントID一時ファイルの作成 (CloudShell: 親アカウント)

手順の目的

一時ファイル名"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-organizations-account-id-parent.txt"を作成します。

設定値の指定

設定値の指定

手順に必要な設定値を変数に格納をします。

1. 一時ファイル用ディレクトリの指定

一時ファイル用ディレクトリを指定します。

変数の設定:

DIR_TMP="${HOME}/tmp-handson-cli-organizations"

ディレクトリが存在することを確認し、存在しない場合は作成します。

コマンド:

ls -d ${DIR_TMP} > /dev/null 2>&1 \
  || mkdir -p ${DIR_TMP}

2. 一時ファイルファイル名の指定

一時ファイルファイル名を指定します。

変数の設定:

FILE_TMP="${DIR_TMP}/handson-cli-organizations-organizations-account-id-parent.txt" \
  && echo ${FILE_TMP}

結果(例):

${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-organizations-account-id-parent.txt

設定値の確認

各変数に正しい設定値が格納されていることを確認しながら保存します。

変数の確認:

cat << END

  # 1. DIR_TMP:"${HOME}/tmp-handson-cli-organizations"
       DIR_TMP="${DIR_TMP}"
  # 2. FILE_TMP:"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-organizations-account-id-parent.txt"
       FILE_TMP="${FILE_TMP}"

END

各変数について、上の行と下の行の値の内容もしくは形式が同じであることを確認します。 もし異なる場合は、それぞれの手順番号に戻って変数の設定を行います。

処理の実行

親アカウントのAWSアカウントIDを取得します。

コマンド:

ORGANIZATIONS_ORGANIZATION_MASTER_ACCOUNT_ID=$( \
  aws organizations describe-organization \
    --query "Organization.MasterAccountId" \
    --output text \
) \
  && echo ${ORGANIZATIONS_ORGANIZATION_MASTER_ACCOUNT_ID}

結果(例):

XXXXXXXXXXXX

一時ファイルを作成します。

変数の確認:

cat << END

  # FILE_TMP:"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-organizations-account-id-parent.txt"
    FILE_TMP="${FILE_TMP}"
  # ORGANIZATIONS_ORGANIZATION_MASTER_ACCOUNT_ID:"XXXXXXXXXXXX"
    ORGANIZATIONS_ORGANIZATION_MASTER_ACCOUNT_ID="${ORGANIZATIONS_ORGANIZATION_MASTER_ACCOUNT_ID}"

END

コマンド:

cat << EOF > ${FILE_TMP}
ORGANIZATIONS_ACCOUNT_ID_PARENT="${ORGANIZATIONS_ORGANIZATION_MASTER_ACCOUNT_ID}"
EOF

cat ${FILE_TMP}

結果(例):

ORGANIZATIONS_ACCOUNT_ID_PARENT="XXXXXXXXXXXX"

完了確認

「一時ファイルファイル名"${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-organizations-account-id-parent.txt"が存在する。」ことを確認します。

コマンド:

ls ${FILE_TMP}

結果(例):

${HOME}/tmp-handson-cli-organizations/handson-cli-organizations-organizations-account-id-parent.txt

手順の完了