Home > Blockchain >  Create a local secondary index using Cloud CloudFormation
Create a local secondary index using Cloud CloudFormation

Time:05-31

My apologies I'm starting with AWS and Cloudformation

I got this cloud formation template, I got Id and topic as a primary index and I would like to add a local secondary index that consists of the id and position columns to this template.

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

CodePudding user response:

You have to add 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
  • Related