首页 > 解决方案 > cloudformation中的字符串,列表和字符串列表有什么区别?

问题描述

cloudformation中的字符串,列表和字符串列表有什么区别?

当我使用 if 条件在 dynamodb 中提供 NonKeyAttributes 时。当我尝试使用 if 条件提供新条件 z 时,我得到属性 NonKeyAttributes 的值必须是字符串列表类型。还有没有更好的方法来做到这一点而不是太多 if 条件

条件: x: !Or [ !Equals [ !Ref env, "prod" ], !Equals [ !Ref env, "acpt" ] ] y: !Or [ !Equals [ !Ref env, "infrastructure" ], !Equals [ !Ref env, "cont" ] ] z: ! 或 [ !Equals [ !Ref env, "dev" ], !Equals [ !Ref env, "test" ], [ !Ref env, "prod" ], !等于 [ !Ref env, "cont" ] ]

Type: "AWS::DynamoDB::Table"
Properties:
  TableName: Employer
  AttributeDefinitions:
    - AttributeName: "empID"
      AttributeType: "S"
    - AttributeName: "TeamID"
      AttributeType: "S"
    - AttributeName: "Date"
      AttributeType: "N"
  KeySchema:
    - AttributeName: "empID"
      KeyType: "HASH"
  ProvisionedThroughput:
    ReadCapacityUnits: 20
    WriteCapacityUnits: 20
  StreamSpecification: 
    StreamViewType: NEW_AND_OLD_IMAGES
  PointInTimeRecoverySpecification:
    PointInTimeRecoveryEnabled: true
  GlobalSecondaryIndexes:
    - IndexName: "ByTeamID"
      KeySchema:
      - AttributeName: "TeamID"
        KeyType: "HASH"
      - AttributeName: "Date"
        KeyType: "RANGE"
      Projection:
        NonKeyAttributes:
          - "A"
          - "B"
          - "C"
          - "D"
          - !If [x, "x1", !Ref "AWS::NoValue"]
          - !If [y, "y1", !Ref "AWS::NoValue" ]
          - !If 
              - z
              - - "z1"
              - - "z2"
              - - "z3"
              - - "z4"
              - !Ref AWS::NoValue

标签: amazon-dynamodbamazon-cloudformation

解决方案


如果您真的只需要在条件为真时投影一个属性,并且有多个属性要包含在特定条件下,那么您必须!If对每个属性重复。

Type: "AWS::DynamoDB::Table"
Properties:
  TableName: Employer
  AttributeDefinitions:
    - AttributeName: "empID"
      AttributeType: "S"
    - AttributeName: "TeamID"
      AttributeType: "S"
    - AttributeName: "Date"
      AttributeType: "N"
  KeySchema:
    - AttributeName: "empID"
      KeyType: "HASH"
  ProvisionedThroughput:
    ReadCapacityUnits: 20
    WriteCapacityUnits: 20
  StreamSpecification: 
    StreamViewType: NEW_AND_OLD_IMAGES
  PointInTimeRecoverySpecification:
    PointInTimeRecoveryEnabled: true
  GlobalSecondaryIndexes:
    - IndexName: "ByTeamID"
      KeySchema:
      - AttributeName: "TeamID"
        KeyType: "HASH"
      - AttributeName: "Date"
        KeyType: "RANGE"
      Projection:
        NonKeyAttributes:
          - "A"
          - "B"
          - "C"
          - "D"
          - !If [x, "x1", !Ref "AWS::NoValue"]
          - !If [y, "y1", !Ref "AWS::NoValue" ]
          - !If [z, "z1", !Ref "AWS::NoValue" ]
          - !If [z, "z2", !Ref "AWS::NoValue" ]
          - !If [z, "z3", !Ref "AWS::NoValue" ]
          - !If [z, "z4", !Ref "AWS::NoValue" ]

推荐阅读