New to AWS DynamoDB?
Tags: dynamodb, aws, consultant
Published: 2020-11-24 12:22:01

# if (you Don't Have DynamoDB Yet) {

In this case I would strongly recommend to not use DynamoDB.
Instead of it go with PostgresQL or MongoDB or anything else.

DynamoDB scales pretty well, but it's very annoying for developers. Just pick another one even [AWS DocumentDB](https://aws.amazon.com/es/documentdb/) or you can go with AWS RDS - PostgreSQL/MySQL](https://aws.amazon.com/rds/)


# }
# if (you Have DynamoDB Already) {


#### Pagination Nightmare

This is something that I only seen with DynamoDB. You can do a Scan or a Query and you only will have a page so you will have to iterate. If you want to dig: [DynamoDB Pagination](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.Pagination.html).

When I reached DynamoDB it was for a legacy system that I had to improved. This is the first thing I didn't like it. I've worked with [MongoDB](https://www.mongodb.com/what-is-mongodb), [Couchbase](https://www.couchbase.com/), [MySQL](https://www.mysql.com/) and PostgreSQL along with others and never seen something like this. The the bottomline is that if you want all the records of the database you will have to iterate.

#### Scan vs Query

In any Database the indexes are useful to speed the queries and make those very performant. In DynamoDB if you don't have a "partition index" or a "global secondary index" you are not allowed to do a Query. The option then is to do Scan that is painfully slowly since it retrieves all the data and then you can use filters but again it is like getAll and then filter over that collection. This means that you have to think in advance how you want to access the data. And think which are your fields that you'll have queries. In a refactor of an existing table I did that work and I added 3 GlobalSecondaryIndexes for 3 different queries.


#### Partition Index vs GlobalSecondaryIndex

[AWS GlobalSecondaryIndexes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html)

[AWS PartitionKey](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey)

#### Environments? Prefix vs Region vs Different Accounts.

I dig into the situation of having to have:

a) A local environment.
b) development, test vs production environments


##### A local environment

1. **Setting up the Local Environment:**
[Document for Setting up Env](https://medium.com/@vschroeder/install-a-local-dynamodb-development-database-on-your-machine-82dc38d59503)

2. **Copying from AWS to Local**
Use one of the tools that I have in the tools section to read a table and write it to the local.

##### development, test vs production environments

I do not like this approach but it is the recommendation from AWS is to use a prefix so you would have users and dev_users which is the **"development environment table"**.


#### Tools

*There is a lack of good tools for DynamoDB there are a few that are decent but paid.*


a. AWS DynamoDB tool [NoSQLWorkbench](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/workbench.html)

Some considerations about the AWS NoSQLWorkbench it is useful to design a little bit the new tables or collections (name it as you wish). But for queries kind of sucks, The main reason is because of Pagination.

b. AWS DynamoDB Web Console:

![AWS DynamoDB Web Console](https://dev-to-uploads.s3.amazonaws.com/i/me4x17jzqhfclkmzwan2.png)

c. Dynobase (Paid):

[Dynobase UI](https://www.electronjs.org/apps/dynobase)

d. A npm tool I built to copy tables between environments and regions or even within the same region but a different prefix:

[aws_dynamo_copy_table](https://www.npmjs.com/package/aws_dynamo_copy_table)

# }