3.1. Cognitoユーザプールスキーマドキュメントの作成 (handson-cli-cognito-idp-userpool)

作業の目的 [why]

Cognito ユーザプール名"handson-cli-cognito-idp-userpool"のためのCognito ユーザプールスキーマドキュメント名"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"を作成します。

完了条件/事前条件 [設計者用情報]

完了条件 [after]

主処理は、以下を満たしたときに成功したものとします。

完了条件1

Cognitoユーザプールスキーマドキュメント"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"が存在する。

事前条件 [before]

主処理の実施は、以下の状態であることを前提とします。

事前条件1

Cognitoユーザプールスキーマドキュメント用ディレクトリ"${HOME}/environment/conf-handson-cli-cognito-idp"が存在する。

事前条件2

Cognitoユーザプールスキーマドキュメント"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"が存在しない。

作業対象 [what]

  • Cognito ユーザプールサービス

標準時間(合計)

8分

パラメータ設定

パラメータ設定の標準時間

2分

作業に必要なモノ・情報 [resource]

作業開始には、以下が全て揃っていることが必要です。

リソース1: Cognitoユーザプール名

  • 作成するCognitoユーザプールの名称です。

  • 今回は"handson-cli-cognito-idp-userpool"とします。

リソース2: Cognito ユーザプールスキーマドキュメント用ディレクトリ

  • 今回は"${HOME}/environment/conf-handson-cli-cognito-idp"をCognitoユーザプールスキーマドキュメント用ディレクトリとします。

ディレクトリが存在することを確認します。

コマンド:

ls -d ${HOME}/environment/conf-handson-cli-cognito-idp

結果(例:存在する場合):

${HOME}/environment/conf-handson-cli-cognito-idp

存在しない場合は作成します。

コマンド:

mkdir -p ${HOME}/environment/conf-handson-cli-cognito-idp

リソース3: Cognito ユーザプールスキーマドキュメントファイル

  • 今回は"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"をCognitoユーザプールスキーマドキュメントファイルとします。

パラメータの指定

作業に必要なパラメータを変数に格納をします。

0.0. リージョンの指定

変数の設定

export AWS_DEFAULT_REGION='ap-northeast-1'

0.1. Cognitoユーザプール名の指定

Cognitoユーザプール名を指定します。

変数の設定:

COGNITO_IDP_USER_POOL_NAME='handson-cli-cognito-idp-userpool'

0.2. Cognitoユーザプールスキーマドキュメント用ディレクトリの指定

変数の設定:

DIR_COGNITO_IDP_USER_POOL_SCHEMA="${HOME}/environment/conf-handson-cli-cognito-idp"

0.3. Cognitoユーザプールスキーマドキュメントファイルの指定

変数の設定:

FILE_COGNITO_IDP_USER_POOL_SCHEMA="${DIR_COGNITO_IDP_USER_POOL_SCHEMA}/${COGNITO_IDP_USER_POOL_NAME}.json" \
  && echo ${FILE_COGNITO_IDP_USER_POOL_SCHEMA}

結果(例):

${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json

パラメータの保存

設定されている変数の保存先となるファイル名を指定します。

変数の設定:

DIR_PARAMETER="${HOME}/tmp/parameter-handson-cli-cognito-idp"
FILE_PARAMETER="${DIR_PARAMETER}/$(date +%Y-%m-%d)-cognito_idp-user_pool_schema_document-create.env" \
  && echo ${FILE_PARAMETER}

結果(例):

${HOME}/tmp/parameter-handson-cli-cognito-idp/2019-12-11-cognito_idp-user_pool_schema_document-create.env

各変数に正しいパラメータ値が格納されていることを確認しながら保存します。

変数の確認:

cat << EOF > ${FILE_PARAMETER}

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

  # 0.1. COGNITO_IDP_USER_POOL_NAME:"handson-cli-cognito-idp-userpool"
         COGNITO_IDP_USER_POOL_NAME="${COGNITO_IDP_USER_POOL_NAME}"
  # 0.2. DIR_COGNITO_IDP_USER_POOL_SCHEMA:"${HOME}/environment/conf-handson-cli-cognito-idp"
         DIR_COGNITO_IDP_USER_POOL_SCHEMA="${DIR_COGNITO_IDP_USER_POOL_SCHEMA}"
  # 0.3. FILE_COGNITO_IDP_USER_POOL_SCHEMA:"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"
         FILE_COGNITO_IDP_USER_POOL_SCHEMA="${FILE_COGNITO_IDP_USER_POOL_SCHEMA}"

EOF

cat ${FILE_PARAMETER}

下段の変数が入っていない、もしくは上段と同等の値が入っていない場合は、それぞれの手順番号に戻って変数の設定を行います。

タスクの実施

タスク標準時間

6分

1. 前処理

処理対象の状態確認

主処理の実施は、以下の状態であることを前提とします。

前提と異なることが判明した場合、直ちに処理を中止します。

事前条件1: Cognitoユーザプールスキーマドキュメント用ディレクトリ"${HOME}/environment/conf-handson-cli-cognito-idp"が存在する。

「Cognitoユーザプールスキーマドキュメント用ディレクトリ"${HOME}/environment/conf-handson-cli-cognito-idp"が存在する。」ことを確認します。

コマンド:

ls -d ${DIR_COGNITO_IDP_USER_POOL_SCHEMA}

結果(例):

${HOME}/environment/conf-handson-cli-cognito-idp

事前条件2: Cognitoユーザプールスキーマドキュメント"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"が存在しない。

「Cognitoユーザプールスキーマドキュメント"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"が存在しない。」ことを確認します。

コマンド:

! ls ${FILE_COGNITO_IDP_USER_POOL_SCHEMA}

結果(例):

ls: ${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json No such file or directory

2. 主処理

Cognitoユーザプールスキーマドキュメントの作成

コマンド:

cat << EOF > ${FILE_COGNITO_IDP_USER_POOL_SCHEMA}
[
    {
        "Name": "sub",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": false,
        "Required": true,
        "StringAttributeConstraints": {
            "MinLength": "1",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "given_name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "family_name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "middle_name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "nickname",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "preferred_username",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "profile",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "picture",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "website",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "email",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": true,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "email_verified",
        "AttributeDataType": "Boolean",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false
    },
    {
        "Name": "gender",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "birthdate",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "10",
            "MaxLength": "10"
        }
    },
    {
        "Name": "zoneinfo",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "locale",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "phone_number",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "address",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "updated_at",
        "AttributeDataType": "Number",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "NumberAttributeConstraints": {
            "MinValue": "0"
        }
    }
]
EOF
cat ${FILE_COGNITO_IDP_USER_POOL_SCHEMA}

結果(例):

[
    {
        "Name": "sub",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": false,
        "Required": true,
        "StringAttributeConstraints": {
            "MinLength": "1",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "given_name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "family_name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "middle_name",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "nickname",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "preferred_username",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "profile",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "picture",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "website",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "email",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": true,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "email_verified",
        "AttributeDataType": "Boolean",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false
    },
    {
        "Name": "gender",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "birthdate",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "10",
            "MaxLength": "10"
        }
    },
    {
        "Name": "zoneinfo",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "locale",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "phone_number",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "address",
        "AttributeDataType": "String",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "StringAttributeConstraints": {
            "MinLength": "0",
            "MaxLength": "2048"
        }
    },
    {
        "Name": "updated_at",
        "AttributeDataType": "Number",
        "DeveloperOnlyAttribute": false,
        "Mutable": true,
        "Required": false,
        "NumberAttributeConstraints": {
            "MinValue": "0"
        }
    }
]

JSONファイルを作成したら、フォーマットが壊れてないか必ず確認します。

エラーが出力されなければOKです。

コマンド:

jsonlint -q ${FILE_COGNITO_IDP_USER_POOL_SCHEMA}

結果(例):

(出力なし)

3. 後処理

完了条件の確認

主処理は、以下を満たしたときに成功したものとします。

完了条件1: Cognitoユーザプールスキーマドキュメント"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"が存在する。

「Cognitoユーザプールスキーマドキュメント"${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json"が存在する。」ことを確認します。

コマンド:

ls ${FILE_COGNITO_IDP_USER_POOL_SCHEMA}

結果(例):

${HOME}/environment/conf-handson-cli-cognito-idp/handson-cli-cognito-idp-userpool.json

完了