Skip to content

Latest commit

 

History

History
59 lines (50 loc) · 2.64 KB

File metadata and controls

59 lines (50 loc) · 2.64 KB

DynamoDBAndNodejs

Simple POC to use DynamoDB with Node.js

Step-By-Step

  • First install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Note that you must have unzip installed. If you don't, install it by running sudo apt-get install unzip

  • Now you must have DynamoDB on the run (AWS) or locally. To install locally, you will need Docker. The image used to run DynamoDB locally is amazon/dynamodb-local. You can run it on your computer by typing on a terminal:
docker run --rm -p 8000:8000 -d amazon/dynamodb-local
  • You`ll need AWS SDK For Javascript in order to run this examples. There are two versions: v2 and v3. The primary changes between them is that v3 is modularized (so you won't need to download every single package out there just to run one service from AWS) and have a middleware stack to control the lifecycle of an operation call. To install v2, do:
yarn add aws-sdk

To install v3 for DynamoDB, do:

yarn add @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb @aws-sdk/util-dynamodb

You may reference to the commits in order to see the differences between v2 and v3 SDKs.

  • To run locally, you need to AWS configure. To do that, follow this:
$ aws configure
AWS Access Key ID []: local
AWS Secret Access Key []: local
Default region name []: us-east-1
Default output format [None]:

Running this POC

  • Git clone this repository:
git clone https://github.com/Guilospanck/DynamoDBAndNodejs.git
  • Run yarn install to install depedencies.

  • Be sure to have the image in Docker up and running (see Step-By-Step for more information).

  • And then run:

node src/table/createTable.js    // to create a new DynamoDB table
node src/item/insertItem.js      // to insert a new item in the table
node src/item/getItem.js         // to get the new item inserted

Referencies