1

I need to create a cloudformation template for my dynamodb, but I need one of the indexes to be incremented automatically. CloudFormation template looks like this:

TestTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: test-event-records
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - AttributeName: “UniqueId”
          AttributeType: “N”
        - AttributeName: “IsRestored”
          AttributeType: “B”
        - AttributeName: “EventName”
          AttributeType: “S”
      KeySchema:
        - AttributeName: “UniqueId”
          KeyType: “HASH”
        - AttributeName: “IsRestored”
          KeyType: “HASH”
        - AttributeName: “EventName”
          KeyType: “HASH”
      Tags:
        - Key: “AppGroup”
          Value: !Ref “AppGroup”
        - Key: “AppRole”
          Value: “database”
        - Key: “Environment”
          Value: !Ref “Environment”
        - Key: “Name”
          Value: “test-event-records”
      StreamSpecification:
        StreamViewType: NEW_IMAGE

Here UniqueId (is of the type number and cannot be a UUID) has to be an auto-incremented value. I need to add new items to this new table in my .net core app.

  • I already seen this post: https://stackoverflow.com/questions/37072341/how-to-use-auto-increment-for-primary-key-id-in-dynamodb#:~:text=DynamoDB%20does%20not%20support%20auto,be%20up%20to%202048%20bytes. However it doesn't answer my question – PurpleGreen Jan 25 '22 at 10:15
  • 1
    Unrelated but please be careful with using any sort of editor which makes those "curly quotes". Those are not real quote characters and I expect if you copy/pasted that into a yaml file and tried to deploy it, it would fail. – 404 Jan 25 '22 at 11:46
  • Thanks for the heads up, I copied it from Brackets. I need to change its settings. – PurpleGreen Jan 25 '22 at 12:08
  • 1
    @Marcin I think I found my answer. It is not possible to do it from cloudformation. But it is possible to auto increment it in the code (in my case it is .netcore). I found this article very helpful https://andrewchaa.me.uk/technical/auto-increment-counter-in-dynamodb/ – PurpleGreen Jan 28 '22 at 10:39

1 Answers1

3

Its not possible. CloudFormation nor DynamoDB provide such functionality. You must implement that in your application.

Marcin
  • 215,873
  • 14
  • 235
  • 294