Amazon dynamodb 在cloudformation中,字符串、列表和字符串列表之间有什么区别?

Amazon dynamodb 在cloudformation中,字符串、列表和字符串列表之间有什么区别?,amazon-dynamodb,amazon-cloudformation,Amazon Dynamodb,Amazon Cloudformation,在cloudformation中,字符串、列表和字符串列表之间有什么区别 当我在dynamodb中使用if条件提供非键属性时。 当我试图用if条件设置新条件z时,我得到了属性NonKeyAttributes的值必须是字符串列表类型。 还有没有更好的方法来代替过多的if条件 条件: x:!或[!Equals[!Ref env,“prod”],!Equals[!Ref env,“acpt”] y:!或[!Equals[!Ref env,“infrastructure”],!Equals[!Ref e

在cloudformation中,字符串、列表和字符串列表之间有什么区别

当我在dynamodb中使用if条件提供非键属性时。 当我试图用if条件设置新条件z时,我得到了属性NonKeyAttributes的值必须是字符串列表类型。 还有没有更好的方法来代替过多的if条件

条件: x:!或[!Equals[!Ref env,“prod”],!Equals[!Ref env,“acpt”] y:!或[!Equals[!Ref env,“infrastructure”],!Equals[!Ref env,“cont”] z:!或[!Equals[!Ref env,“dev”],!Equals[!Ref env,“test”],[!Ref env,“prod”],!Equals[!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", !Ref "AWS::NoValue" ]
          - !If [z, "z2", !Ref "AWS::NoValue" ]
          - !If [z, "z3", !Ref "AWS::NoValue" ]
          - !If [z, "z4", !Ref "AWS::NoValue" ]

您是试图在某些情况下仅投影属性,还是这些属性仅在某些情况下存在?换句话说,如果某个条件为真,您是说只有项目X,还是说只有当某个条件为真时,X才会存在,所以您不想包含它?如果X条件为真,那么它将提供x1值。当条件满足时,如果它只有一个值,我就可以这样做。但在z条件下,我有超过z1,z2,z3I的值,我这样做了,它工作了。但是有没有其他方法可以避免多次重复的if条件呢?我想不出来。老实说,我从来没有考虑过投影是我可以做的事情。如果数据不同,我只会包括所有变量。我认为如果数据中没有属性,它就不会在意了。如果您真的希望数据中始终存在的值有条件地存在于GSI中,那么我认为您必须这样做。
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" ]