Multiple DynamoDB tables to one service


Hi there,

I’am trying to expand the notes api with some more tables.
Currently I have added a few more dynamodb-tables-XYZ.yml files and referenced them at the bottom in my serverless.yml file (under ressources).

But how do I implement multiple “custom” blocks in one serverless.yml file (at the top of the file) where it describes the naming convention used for specific environments, more specific:

  # Our stage is based on what is passed in when running serverless
  # commands. Or fallsback to what we have set in the provider section.
  stage: ${opt:stage, self:provider.stage}
  # Set the table name here so we can use it while testing locally
  tableName: ${self:custom.stage}-notes
  # Set our DynamoDB throughput for prod and all other non-prod stages.
    prod: 5
    default: 1
  tableThroughput: ${self:custom.tableThroughputs.${self:custom.stage}, 
  # Load our webpack config
    webpackConfig: ./webpack.config.js
    includeModules: true
  # Load our secret environment variables based on the current stage.
  # Fallback to default if it is not in prod.
  environment: ${file(env.yml):${self:custom.stage}, file(env.yml):default}

Kind regards


Maybe the answer relies in this part of the book? if I follows theese steps I might be able to ad more tables and api’s and tie them together?

Kind regards

  • Tony


Hmm I’m not sure what you mean by multiple custom blocks. You can keep adding that block up top. Can you give me an example of what you are looking to do?


By multiple custom blocks i mean a way to add more tables in the serverless.yml file. Right now there is one custom block that contains the definition for one table. But if I have more than one table, how woul my serverless.yml file look like, more precisely the custom block?
Right now I’am following this chapter so maybe it will fix the problem for me (at least I think so for now).


I don’t think there is any restriction in the number of things you can define in a custom block. So you can use different variable names for the different tables and they should work fine.


You might want to read through the AWS guide for Serverless to get a better understanding of the serverless.yml file I was still a bit in the dark after finishing the tutorial, until I reviewed it.

If I understand your question, though, to add another table, you need to create another table declaration in one of the Resources sections, so either in the main serverless.yml file, or in one of the sub files (likely dynamodb-table.yml).

Not to go too far off on a tangent, but you might want to look into NoSQL table design best practices, as you can avoid adding tables through well-planned key design.