# AWS Dynamodb with same structure

**URL:** <https://forum.serverless.com/t/aws-dynamodb-with-same-structure/4550>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [May 23, 2018, 3:15am UTC](https://forum.serverless.com/t/aws-dynamodb-with-same-structure/4550 "2018-05-23T03:15:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![resting](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/resting/32/1716_2.png) [@resting](https://forum.serverless.com/u/resting)\
**Post date:** [May 23, 2018, 3:15am UTC](https://forum.serverless.com/t/aws-dynamodb-with-same-structure/4550/1 "2018-05-23T03:15:28Z")

</div>

In my current `serverless.yml` I have the following resource declaration:

```auto
resources:
  Resources:
    stocksTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.stocksTableName}
        AttributeDefinitions:
          -
            AttributeName: symbol
            AttributeType: S
          -
            AttributeName: dateiso
            AttributeType: S
          -
            AttributeName: monthIdx
            AttributeType: S
        KeySchema:
          -
            AttributeName: symbol
            KeyType: HASH
          -
            AttributeName: dateiso
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        GlobalSecondaryIndexes:
          - 
            IndexName: monthIdx
            KeySchema:
              - 
                AttributeName: monthIdx
                KeyType: HASH
              - 
                AttributeName: dateiso
                KeyType: RANGE
            Projection:
              ProjectionType: ALL
            ProvisionedThroughput:
              ReadCapacityUnits: 1
              WriteCapacityUnits: 1

```

Now, I need to add a **second** table with exactly the **same** structure and indexes.

Do I need to duplicate the entire entry for the new resource?

**Option1**

```auto
resources:
  Resources:
    stocksTable:
      {declarations}
    stocks2Table:
      {declarations copied}

```

Or can I do something like this:

**Option2:**

```auto
resources:
  Resources:
    stocksTable:
    stocks2Table:
      {declarations}

```

But the `TableName` will be a problem with option 2.

```auto
resources:
  Resources:
    stocksTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.stocksTableName}

```

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [May 23, 2018, 12:27pm UTC](https://forum.serverless.com/t/aws-dynamodb-with-same-structure/4550/2 "2018-05-23T12:27:08Z")

</div>

The simplest solution I can think of will look something like:

```auto
custom:
  commonTableProps: &commonTableProps
    AttributeDefinitions:
      -
        AttributeName: symbol
        AttributeType: S
      -
        AttributeName: dateiso
        AttributeType: S
      -
        AttributeName: monthIdx
        AttributeType: S
    KeySchema:
      -
        AttributeName: symbol
        KeyType: HASH
      -
        AttributeName: dateiso
        KeyType: RANGE
    ProvisionedThroughput:
      ReadCapacityUnits: 1
      WriteCapacityUnits: 1
    GlobalSecondaryIndexes:
      - 
        IndexName: monthIdx
        KeySchema:
          - 
            AttributeName: monthIdx
            KeyType: HASH
          - 
            AttributeName: dateiso
            KeyType: RANGE
        Projection:
          ProjectionType: ALL
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1

resources:
  Resources:
    stocksTable:
      Type: AWS::DynamoDB::Table
      Properties:
        <<: *commonTableProps
        TableName: ${self:custom.stocksTableName}
    stocks2Table:
      Type: AWS::DynamoDB::Table
      Properties:
        <<: *commonTableProps
        TableName: ${self:custom.stocks2TableName}

```

---

<div class="post-metadata">

**Author:** ![resting](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/resting/32/1716_2.png) [@resting](https://forum.serverless.com/u/resting)\
**Post date:** [May 24, 2018, 4:17am UTC](https://forum.serverless.com/t/aws-dynamodb-with-same-structure/4550/3 "2018-05-24T04:17:24Z")

</div>

Nice. I think it works.  
Thanks!  
Learnt about the new syntax 🙂
