- Tutorial Home
- Introduction to DynamoDB database
- DynamoDB local and setups required
- DynamoDB Data types tutorial
- Create a table in DynamoDB
- Insert items into DynamoDB table
- Query items in a DynamoDB table
- Scan the DynamoDB table items
- Update an item in the DynamoDB table
- DynamoDB table Index – Global and local
Dynamodb is an AWS managed service. This means you do not need to worry about the infrastructure needed for AWS. You do not need to configure any servers. Directly creating a table in DynamoDB is enough. We can specify the configuration and the required capacity of the table during its creation. We can also use DynamoDB local version for testing.
For the case of testing and development, instead of using AWS resources, It will be nice if we could test it locally. Since AWS DynamoDB is only available for AWS you cannot simply install the production version of DynamoDB in the local environment.
AWS provides a local version of DynamoDB. This is not a production usable version but can be used for testing and development. With this, there will be no AWS cost. You do not need an internet connection to work with local DynamoDB.
There are three ways we can install it:
- DynamoDB (Downloadable Version) on Computer
- DynamoDB (Downloadable Version) and Apache Maven
- DynamoDB (Downloadable Version) and Docker
In this tutorial, we will be using the DynamoDB Docker image for the setup. With docker, it is very easy to setup. Simply run the following command to run DynamoDB in your machine:
docker run -p 8000:8000 amazon/dynamodb-local
|> For running a docker image like above,
make sure you have docker installed in your machine
and you docker demon is running.
The command above will fetch the Docker image. Wait a few minutes till the image gets downloaded.
Once the image is downloaded you will see that the docker is running in a default port 8000.
> docker run -p 8000:8000 amazon/dynamodb-local
Unable to find image ‘amazon/dynamodb-local:latest’ locally
latest: Pulling from amazon/dynamodb-local
638b75f800bf: Pull complete
7d727a2b79b4: Pull complete
c83cc16257dd: Pull complete
Status: Downloaded newer image for amazon/dynamodb-local:latest
Initializing DynamoDB Local with the following configuration:
You have various configuration options while starting the DynamoDB Docker images.
- port – The port you want DynamoDB to server requests. Default: 8000
- inMemory – The database will be set in memory. You will lose the data if the image is stopped/restarted. Default: true
- dbPath – The path where you want DynamoDB to store the data file. If not specified the value is stored in the current directory. You cannot use this option with InMeory enabled.
- optimizeDbBeforeStartup – optimize the backing database tables before server starts.
- sharedDb – DynamoDB will store all data in a file shared-local-instance.db. If you do not set it, the file will be myaccesskeyid_region.db Default: false
- delayTransientStatuses – Since local DB completes its request instantly to simulate network you can add some delay using this option.
You need to specify -jar option before specifying any above options. An example of using the configuration:
docker run -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb
DynamoDB from AWS console
Go to the AWS console. In the top navigation search for DynamoDB. In the DynamoDB console, you can go ahead and create a table. We will be creating a table in the next coming sections of this tutorial.
Here you can create your table directly. No need to create a database server. This is fully managed by AWS. All you need to do is create a table with its specifications. We will learn about creating the table in the coming sections.
Now with the setup, we can go ahead and learn about DynamoDb without the need to set up AWS or even having an AWS account.