使用 Cloud CloudFormation 创建本地二级索引

Create a local secondary index using Cloud CloudFormation

抱歉我开始使用 AWS 和 Cloudformation

我得到了这个云形成模板,我得到了 Idtopic 作为主要索引,我想添加一个由 idposition 列到此模板。

Id topic position detaills
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  Env:
    Type: String
  CommitHash:
    Type: String

Resources:
  RecipeRecommendationDynamoDBTable:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
        - AttributeName: "id"
          AttributeType: "S"
        - AttributeName: "topic"
          AttributeType: "S"
      KeySchema:
        - AttributeName: "id"
          KeyType: "HASH"
        - AttributeName: "topic"
          KeyType: "RANGE"
      TimeToLiveSpecification:
        AttributeName: ttl
        Enabled: true
      TableName: topics_dumps
      BillingMode: PAY_PER_REQUEST
      Tags:
        - Key: "Env"
          Value: !Ref Env

您必须添加 LocalSecondaryIndexes:

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  Env:
    Type: String
  CommitHash:
    Type: String

Resources:
  RecipeRecommendationDynamoDBTable:
    Type: AWS::DynamoDB::Table
    Properties:
      AttributeDefinitions:
        - AttributeName: "id"
          AttributeType: "S"
        - AttributeName: "topic"
          AttributeType: "S"
        - AttributeName: "position"
          AttributeType: "S"          
      KeySchema:
        - AttributeName: "id"
          KeyType: "HASH"
        - AttributeName: "topic"
          KeyType: "RANGE"
      TimeToLiveSpecification:
        AttributeName: ttl
        Enabled: true
      LocalSecondaryIndexes: 
        - IndexName: position
          KeySchema: 
            - AttributeName: "id"
              KeyType: "HASH"
            - AttributeName: "position"
              KeyType: "RANGE"           
          Projection: 
            ProjectionType: ALL
      TableName: topics_dumps
      BillingMode: PAY_PER_REQUEST
      Tags:
        - Key: "Env"
          Value: !Ref Env