
AWS CDK で IAM Role に Amazon Cognito User Pools のポリシーを設定する場合は grant(grantee, ...actions) メソッドを使う.
第二引数の ...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)
ちなみにポリシーのサンプルは以下のドキュメントを参考にした📝
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 もあった👀