如何在 CloudFormation 中为 IndentityPoolRoleAttachment 设置动态 RoleMappings 键

Akk*_*nZA 5 json amazon-web-services aws-cloudformation amazon-cognito

我正在构建一个堆栈来初始化Cognito安装。作为其中的一部分,我设置了具有关联角色的用户组。我需要设置该Choose role from token选项,允许身份使用其分配到的组中的角色。

这是通过对象RoleMappings中的对象来完成的IndentityPoolRoleAttachment。该映射对象是一个string -> object映射,其中字符串代表身份提供者。就我而言,这是:

cognito-idp.${some-region}.amazonaws.com/${some-userpool-id}:${some-pool-client-id}

显然,这需要根据堆栈中的值动态构建,但我还没有找到一种方法以语法正确的方式做到这一点。使用RefandFn::Sub都会导致语法错误。我已经尝试过 yaml 和 json 语法。

我错过了一些明显的东西吗?

kke*_*ley 2

最近遇到了这个问题,我访问了@AkkarinZA 评论中的线程。

在那条线索中,@mikef 的回应对我有用。我们可以使用cognitoProvider密钥。

RoleMappings:
     cognitoProvider:
       IdentityProvider: 
        Fn::Join:
          - ''
          - - "cognito-idp.${self:provider.region}.amazonaws.com/"
            - !Ref CustomerUserPool
            - ':'
            - !Ref CustomerUserPoolClient
       AmbiguousRoleResolution: Deny
       Type: Rules
       RulesConfiguration:
          Rules:
            - Claim: cognito:groups
              MatchType: Contains
              Value: "clients"
              RoleARN:
                { Fn::GetAtt: [UserIdentityPoolClientRole, Arn] }

Run Code Online (Sandbox Code Playgroud)