AWS CloudFormation - 任何使用内部函数作为对象键的方法?

AWS CloudFormation - Any way to use an intrinsic function as an object key?

我有这个角色附件资源,部署得很好:

CognitoIdentityPoolRoleAttachment:
  DependsOn: [ CognitoIdentityPool, CognitoIdentityPoolAuthRole, CognitoIdentityPoolUnauthRole ]
  Type: "AWS::Cognito::IdentityPoolRoleAttachment"
  Properties:
    IdentityPoolId: !Ref CognitoIdentityPool
    RoleMappings:
      'cognito-idp.us-west-2.amazonaws.com/us-west-2_naEXQTLxD:44rd7mu8dncna2kqimd74f7u98':
        Type: Token
        AmbiguousRoleResolution: AuthenticatedRole
    Roles:
      unauthenticated: !GetAtt CognitoIdentityPoolUnauthRole.Arn
      authenticated: !GetAtt CognitoIdentityPoolAuthRole.Arn

但是,如您所见,我有一个 RoleMappings 属性,它实际上是我的 CognitoUserPool ProviderName 附加到我的 Cognito 用户池客户端 ID,所以我需要这个 属性 来拥有一个动态名称。

但是,查看文档后,我找不到在对象键上实际使用内部函数的方法。当我尝试这个时:

  RoleMappings:
    !Sub '${CognitoUserPool.ProviderName}:${CognitoUserPoolClient}':
      Type: Token
      AmbiguousRoleResolution: AuthenticatedRole

我收到无效模板错误。是否有我缺少的特殊语法允许您定义键而不是属性?还是我必须以其他方式来做这件事?

无法使用 CloudFormation 开箱即用。 但是,this thread 建议使用涉及 Lambda-backed 自定义资源的解决方法。