Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using getItem with primary and sort keys

So i have a dynamodb table called tableX with the fields:

random_fld1, random_fld2, primary_key1, and sort_key1
all fields are Strings. 

What would be a getItem example with those keys and fields. I haven't been able to get the Keys: portion working with getItem.

like image 509
Messak Avatar asked Jan 03 '23 18:01

Messak


1 Answers

You can use DynamoDB's DocumentClient get() as:

'use strict';

const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({ apiVersion: '2012-08-10' });

var params = {
  TableName: 'tableX',
  Key: {
    'primary_key1': 'PARTITION_KEY_VALUE',
    'sort_key1': 'SORT_KEY_VALUE'
  }
};

docClient.get(params, function(err, data) {
  if (err) console.log(err);
  else     console.log(data);
});

See the documentation.

like image 60
Khalid T. Avatar answered Jan 06 '23 11:01

Khalid T.