# Dynamo Db Table Resource Definition Example with Sort Key

**URL:** <https://forum.serverless.com/t/dynamo-db-table-resource-definition-example-with-sort-key/3151>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [November 20, 2017, 4:38am UTC](https://forum.serverless.com/t/dynamo-db-table-resource-definition-example-with-sort-key/3151 "2017-11-20T04:38:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![x11joe](https://avatars.discourse-cdn.com/v4/letter/x/50afbb/32.png) [@x11joe](https://forum.serverless.com/u/x11joe)\
**Post date:** [November 20, 2017, 4:38am UTC](https://forum.serverless.com/t/dynamo-db-table-resource-definition-example-with-sort-key/3151/1 "2017-11-20T04:38:14Z")

</div>

I have some code in my serverless.yml like this currently.

```
resources:
  Resources:
    uploadBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:service}-${self:custom.stage}-uploads
    visitsTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:custom.visitsTable}
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
          - AttributeName: visitId
            AttributeType: S
          - AttributeName: comments
            AttributeType: S
          - AttributeName: attachments
            AttributeType: S
          - AttributeName: ph
            AttributeType: N
          - AttributeName: ch
            AttributeType: N
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
          - AttributeName: visitId
            KeyType: HASH
        ProvisionedThroughput:
            ReadCapacityUnits: 5
            WriteCapacityUnits: 5

```

My goal is to create a table with primary key userId, sort key visitId and have fields for comments, attachments, ph & ch. When I try to `sls deploy` I get the following error.

Serverless Error ---------------------------------------

An error occurred: visitsTable - Property AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes.

What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![x11joe](https://avatars.discourse-cdn.com/v4/letter/x/50afbb/32.png) [@x11joe](https://forum.serverless.com/u/x11joe)\
**Post date:** [November 20, 2017, 6:28am UTC](https://forum.serverless.com/t/dynamo-db-table-resource-definition-example-with-sort-key/3151/2 "2017-11-20T06:28:00Z")

</div>

I figured out what it was, apparently you are only supposed to define the keys and not the other attributes. Got my answer here, [https://stackoverflow.com/questions/47385177/serverless-framework-dynamo-db-table-resource-definition-with-sort-key/47385697?noredirect=1#comment81725074\_47385697](https://stackoverflow.com/questions/47385177/serverless-framework-dynamo-db-table-resource-definition-with-sort-key/47385697?noredirect=1#comment81725074_47385697)

---

<div class="post-metadata">

**Author:** ![carlosaln](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/carlosaln/32/474_2.png) [@carlosaln](https://forum.serverless.com/u/carlosaln)\
**Post date:** [November 20, 2017, 2:58pm UTC](https://forum.serverless.com/t/dynamo-db-table-resource-definition-example-with-sort-key/3151/3 "2017-11-20T14:58:15Z")

</div>

Something to remember here is that NoSQL databases do not have predefined schema other than the keys with which to represent the item. All other attributes (“columns”) are optional and thus do not need to be declared beforehand.
