Search code examples
amazon-web-servicesamazon-dynamodbaws-cloudformationcicd

Can we create multiple Amazon DynamoDB tables at a time using AWS CloudFormation Template?


I'm trying to create Amazon DynamoDB tables using Cloud Formation Template. So my question is can I have multiple tables created in single go ?

If yes, what would the approach be, to have multiple "Properties" or to have multiple "Resources" ?

Can you please clarify on this.


Solution

  • Each DynamoDB table is a resource of type AWS::DynamoDB::Table.

    Add multiple resources, each with a different table name. For example:

    Resources:
      Users:
        Type: AWS::DynamoDB::Table
        Properties:
          AttributeDefinitions:
          - AttributeName: UserID
            AttributeType: S
          KeySchema:
          - AttributeName: UserID
            KeyType: HASH
      Jobs:
        Type: AWS::DynamoDB::Table
        Properties:
          AttributeDefinitions:
          - AttributeName: UserID
            AttributeType: S
          - AttributeName: JobID
            AttributeType: S
          KeySchema:
          - AttributeName: UserID
            KeyType: HASH
          - AttributeName: JobID
            KeyType: RANGE