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.

1 Like

You should really take some time to check out this video.

You want only one table per service. Stop thinking the same was as if your were implementing relational tables or your services will cost your exponentially more money.

There are very very few use cases that require more than one table.

The important thing to do is to design your SORT keys properly to minimize the READS (RCU) to your NoSQL DB (Dynamo).

From there additional views should be handled with GSI.

Use LSI’s (Local Secondary Indexes) to give you additional ways to sort your views. Please watch this:

1 Like

Yup that’s a great video on how to structure your DynamoDB tables!

im talking crap like I know what im doing and im literally struggling with implementing a query to a GSI right now… lol

What would be a good way to implement a GSI to then write to said GSI? any ideas?


Hmm I’m not familiar with a GSI. What is it?