Quantcast
Channel: プログラミング
Viewing all articles
Browse latest Browse all 8415

AWS CDK で IAM Role に Cognito User Pools の ポリシーを設定する - kakakakakku blog

$
0
0

AWS CDK で IAM Role に Amazon Cognito User Poolsのポリシーを設定する場合は grant(grantee, ...actions)メソッドを使う.

docs.aws.amazon.com

第二引数の ...actionsは可変長引数を受け取るため,以下のようにポリシーを並べて実装できる❗️

userPool.grant(
    role,
    'cognito-idp:AdminCreateUser',
    'cognito-idp:Describe*',
    'cognito-idp:Get*',
    'cognito-idp:List*',
)

もしくはスプレッド構文を使ってポリシーの配列を展開して実装することもできる👌

const actions = ['cognito-idp:AdminCreateUser',
    'cognito-idp:Describe*',
    'cognito-idp:Get*',
    'cognito-idp:List*',
]
userPool.grant(role, ...actions)

ちなみにポリシーのサンプルは以下のドキュメントを参考にした📝

docs.aws.amazon.com

IAM Role をデプロイするとポリシーは期待通りになっていた❗️

{"Version": "2012-10-17",
    "Statement": [{"Action": ["cognito-idp:AdminCreateUser",
                "cognito-idp:Describe*",
                "cognito-idp:Get*",
                "cognito-idp:List*"
            ],
            "Resource": "arn:aws:cognito-idp:ap-northeast-1:000000000000:userpool/ap-northeast-1_xxxxxxxxx",
            "Effect": "Allow"
        }]}

ちなみに今のところ UserPoolクラスには grant()メソッドしかなく,他の L2 コンストラクトに実装されているような grant*()メソッドもあると良いのでは?という issue もあった👀

github.com


Viewing all articles
Browse latest Browse all 8415

Trending Articles