ハンズオン(簡易版): IAM Identity Center基礎

5.2. IdentityStoreグループメンバーシップの作成 (handson-cli-iic-group: ichi)

手順の目的

IdentityStoreユーザー"ichi"が、IdentityStoreグループ"handson-cli-iic-group"に所属するためのメンバーシップを作成します。

設定値の指定

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

0. リージョン

リージョンを指定します。

環境変数の設定:

export AWS_DEFAULT_REGION='ap-northeast-1'

1. IdentityStoreグループ表示名

IdentityStoreグループ表示名を指定します。

変数の設定:

IDENTITYSTORE_GROUP_DISPLAY_NAME='handson-cli-iic-group'

2. IdentityStoreユーザー名

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

変数の設定:

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

変数の設定:

FILE_TMP="${DIR_TMP}/handson-cli-iic-user.tmp" \
  && echo ${FILE_TMP}

結果(例):

${HOME}/environment/tmp-handson-cli-iic/handson-cli-iic-user.tmp

一時ファイルをドットコマンドで読み込みます。

コマンド:

. ${FILE_TMP}

IdentityStoreユーザー名を指定します。

変数の設定:

IDENTITYSTORE_USER_NAME="${USER_NAME}" \
  && echo ${IDENTITYSTORE_USER_NAME}

結果(例):

ichi

設定値の確認

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

変数の確認:

cat << END

  # 0. AWS_DEFAULT_REGION:"ap-northeast-1"
       AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}"

  # 1. IDENTITYSTORE_GROUP_DISPLAY_NAME:"handson-cli-iic-group"
       IDENTITYSTORE_GROUP_DISPLAY_NAME="${IDENTITYSTORE_GROUP_DISPLAY_NAME}"
  # 2. IDENTITYSTORE_USER_NAME:"ichi"
       IDENTITYSTORE_USER_NAME="${IDENTITYSTORE_USER_NAME}"

END

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

処理の実行

IdentityStore IDを取得します。

コマンド:

sso_admin_identity_store_id=$( \
  aws sso-admin list-instances \
    --query "Instances[].IdentityStoreId" \
    --output text \
) \
  && echo ${sso_admin_identity_store_id}

結果(例):

d-xxxxxxxxxx

IdentityStoreグループのIDを取得します。

コマンド:

identitystore_group_id=$( \
  aws identitystore get-group-id \
    --identity-store-id ${sso_admin_identity_store_id} \
    --alternate-identifier "{\"UniqueAttribute\":{\"AttributePath\":\"displayName\",\"AttributeValue\":\"${IDENTITYSTORE_GROUP_DISPLAY_NAME}\"}}" \
  --query "GroupId" \
  --output text \
) \
  && echo ${identitystore_group_id}

結果(例):

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

IdentityStoreユーザーのIDを取得します。

コマンド:

identitystore_user_id=$( \
  aws identitystore get-user-id \
    --identity-store-id ${sso_admin_identity_store_id} \
    --alternate-identifier "{\"UniqueAttribute\":{\"AttributePath\":\"userName\",\"AttributeValue\":\"${IDENTITYSTORE_USER_NAME}\"}}" \
    --query 'UserId' \
    --output text \
) \
  && echo ${identitystore_user_id}

結果(例):

xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

IdentityStoreグループメンバーシップの作成

IdentityStoreグループメンバーシップを作成します。

変数の確認:

cat << END

  # sso_admin_identity_store_id:"d-xxxxxxxxxx"
    sso_admin_identity_store_id="${sso_admin_identity_store_id}"
  # identitystore_group_id:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    identitystore_group_id="${identitystore_group_id}"
  # identitystore_user_id:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    identitystore_user_id="${identitystore_user_id}"

END

コマンド:

aws identitystore create-group-membership \
  --identity-store-id ${sso_admin_identity_store_id} \
  --group-id ${identitystore_group_id} \
  --member-id UserId="${identitystore_user_id}"

結果(例):

{
  "MembershipId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "IdentityStoreId": "d-xxxxxxxxxx"
}

完了確認

「IdentityStoreユーザー"ichi"がIdentityStoreグループ"handson-cli-iic-group"に所属するIdentityStoreグループメンバーシップが存在する。」ことを確認します。

コマンド:

aws identitystore is-member-in-groups \
  --identity-store-id ${sso_admin_identity_store_id} \
  --group-ids ${identitystore_group_id} \
  --member-id UserId=${identitystore_user_id} \
  --query 'Results[].MembershipExists' \
  --output text

結果(例):

True

手順の完了

  • IAM Identity Centerダッシュボード ( https://console.aws.amazon.com/singlesignon/home )にアクセスします。

  • 左ペイン "グループ"をクリックします。

  • 検索フォームにグループ名"handson-cli-iic-group"を入力します。

  • グループ名"handson-cli-iic-group"(リンク)をクリックします。

  • "このグループのユーザー"(セクション)の検索フォームにユーザー名"ichi"を入力します。

  • ユーザー名"ichi"が表示されれば正常です。