Difference between revisions of "DynamoDB"

Line 48: Line 48:
 
$ docker stop $(docker ps -a -q --filter ancestor=amazon/dynamodb-local)
 
$ docker stop $(docker ps -a -q --filter ancestor=amazon/dynamodb-local)
 
</source>
 
</source>
 +
 +
 +
=DynamoDB Notes=
 +
 +
'''To export the data run the following:'''
 +
<source>
 +
$ aws dynamodb scan --table-name my-prod-table \
 +
| jq '{"my-local-table": [.Items[] | {PutRequest: {Item: .}}]}' > data.json
 +
</source>
 +
 +
Basically what happens is that we scan our prod table, transform the output of the scan to shape into the format of the batchWriteItem and dump the result into a file.
 +
 +
'''To import the data in your local table run:'''
 +
<source>
 +
aws dynamodb batch-write-item \
 +
--request-items file://data.json \
 +
--endpoint-url http://localhost:8000
 +
</source>
 +
 +
'''Note:''' There are some restriction with the batch-write-item request - The BatchWriteItem operation can contain up to 25 individual PutItem and DeleteItem requests and can write up to 16 MB of data. (The maximum size of an individual item is 400 KB.).

Revision as of 04:09, 4 May 2020

AWS DynamoDB local

to run AWS DynamoDb on your own machine, you can use official Docker container of AWS.

https://hub.docker.com/r/amazon/dynamodb-local/

Docker pull command :

docker pull amazon/dynamodb-local

DynamoDB local is a downloadable version of DynamoDB that enables developers to develop and test applications using a version of DynamoDB running in your own development environment.

Benefits of using DynamoDB local

The new DynamoDB local Docker image enables you to get started with DynamoDB local quickly by using a docker image with all the DynamoDB local dependencies and necessary configuration built in. The new Docker image also enables you to include DynamoDB local in your containerized builds and as part of your continuous integration testing.

Using DynamoDB local does not require an internet connection and DynamoDB local works with your existing DynamoDB API calls. There are no provisioned throughput, data storage, or data transfer costs with DynamoDB local.

Getting Started with DynamoDB on Docker

Simply run docker run -p 8000:8000 amazon/dynamodb-local to execute DynamoDB locally.

You can find a sample application on GitHub demonstrating how to use DynamoDB local for testing.

To learn how to configure DynamoDB local, see the DynamoDB local usage notes in the AWS Docs.

Examples

$ lsof -i :8000 | grep LISTEN
$ docker run -p 8000:8000 amazon/dynamodb-local
$ aws dynamodb list-tables --endpoint-url http://localhost:8000
$ aws dynamodb create-table --table-name orders_table --attribute-definitions AttributeName=orderId,AttributeType=S --key-schema AttributeName=orderId,KeyType=HASH --billing-mode PAY_PER_REQUEST --endpoint-url http://localhost:8000
$ docker ps --filter ancestor=amazon/dynamodb-local
$ docker stop $(docker ps -a -q --filter ancestor=amazon/dynamodb-local)


DynamoDB Notes

To export the data run the following:

$ aws dynamodb scan --table-name my-prod-table \
| jq '{"my-local-table": [.Items[] | {PutRequest: {Item: .}}]}' > data.json

Basically what happens is that we scan our prod table, transform the output of the scan to shape into the format of the batchWriteItem and dump the result into a file.

To import the data in your local table run:

aws dynamodb batch-write-item \
--request-items file://data.json \
--endpoint-url http://localhost:8000

Note: There are some restriction with the batch-write-item request - The BatchWriteItem operation can contain up to 25 individual PutItem and DeleteItem requests and can write up to 16 MB of data. (The maximum size of an individual item is 400 KB.).