【问题标题】:AWS Cloudformation nested intrinsic function not evaluatingAWS Cloudformation 嵌套内在函数未评估
【发布时间】:2018-10-13 12:22:25
【问题描述】:

这是我正在编写的 cloudformation 模板的一部分,使用 Fn::FindInMap 函数时出现错误:

Parameters:
  VpcStackName:
    Description: >-
      Name of an active CloudFormation VPC stack that contains the networking
      resources, such as the subnet and security group, that will be used in
      this stack.
    Type: String
    MinLength: 1
    MaxLength: 255
    AllowedPattern: '^[a-zA-Z][-a-zA-Z0-9]*$'
    Default: wordpress-dev-vpc

Mappings:
  Instance:
    development:
      AllocatedStorage: 20
      DBInstanceClass: db.t2.micro
    production:
      AllocatedStorage: 25
      DBInstanceClass: db.m3.medium

Resources:
  DBInstance:
      Type: AWS::RDS::DBInstance
      DeletionPolicy: Snapshot
      Properties:
        Engine: MariaDB
        StorageType: gp2
        MasterUsername: !Ref MasterUsername
        MasterUserPassword: !Ref MasterUserPassword
        AllocatedStorage:
          Fn::FindInMap:
            - Instance
            - Fn::ImportValue:
                Fn::Sub: '${VpcStackName}-Environment'
            - AllocatedStorage
        DBInstanceClass:
          Fn::FindInMap:
            - Instance
            - Fn::ImportValue:
                Fn::Sub: '${VpcStackName}-Environment'
            - DBInstanceClass

在另一个堆栈中,我正在像这样导出${VpcStackName}-Environment

Outputs:
  Environment:
    Description: Environment type of this stack
    Value: !Ref Environment
    Export:
      Name: !Sub '${AWS::StackName}-Environment'

尝试使用Fn::FindInMap 函数时,我收到此错误:

An error occurred (ValidationError) when calling the ValidateTemplate operation: Template error: every Fn::FindInMap object requires three parameters, the map name, map key and the attribute for return value

有什么建议吗?

根据 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html 的文档,Fn::FindInMap 函数内支持的函数是 Fn::FindInMapRef。那么还有另一种方法吗?例如,将Fn::ImportValue: !Sub '${VpcStackName}-Environment' 的值存储在临时变量中?

【问题讨论】:

  • 检查此导出值是否可用 ${AWS::StackName}-Environment,我尝试了具有硬编码值的相同模板并且它有效。
  • 是的,导出值可用。我在另一个导入值有效的模板中成功使用了它。出于某种原因,Fn::ImportValue 没有在 Fn::FindInMap 内部得到评估
  • 这有什么更新吗?我也遇到了同样的问题。

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


【解决方案1】:

根据this 文档,Fn::FindInMap 函数只能用于这些:

  • Fn::FindInMap
  • 参考

所以Fn::ImportValueFn::Sub 不会被评估。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多