【问题标题】:AWS CloudFormation - Any way to use an intrinsic function as an object key?AWS CloudFormation - 有什么方法可以使用内部函数作为对象键?
【发布时间】:2018-08-06 06:50:35
【问题描述】:

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

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

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

【问题讨论】:

  • 我认为这里最简单的解决方案是使用外部脚本生成模板。您还可以尝试创建一个自定义资源来生成模板,然后从该模板创建一个堆栈,使用AWS::CloudFormation::Stack 和该资源的结果。

标签: amazon-web-services amazon-cloudformation amazon-cognito


【解决方案1】:

无法使用 CloudFormation 开箱即用地执行此操作。 但是,this thread 建议了一种涉及 Lambda 支持的自定义资源的解决方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多