0
const dynamoDB = new AWS.DynamoDB.DocumentClient();
    var params: any = {};
    params.TableName = 'StockDailyCandles';
    var key = { 'symbol': 'AAPL', 'datetime': '640590008898' }; // example timestamp
    params.Key = key;

    var x = await dynamoDB.get(params).promise();
    return (x.Item ? true : false);

enter image description here

The composite key for the table is symbol, and "datetime"(which is simply a timestamp). Both columns are set as strings in dynamodb.

The error im receiving is : The provided key element does not match the schema

user1698144
  • 754
  • 4
  • 13
  • 36
  • Yes - it is.... – user1698144 Nov 03 '20 at 20:52
  • Doesn't dynamo expect an ISO 8601 string for datetimes if you are passing a string? [see also](https://stackoverflow.com/questions/40561484/what-data-type-should-be-use-for-timestamp-in-dynamodb) – Mark Nov 03 '20 at 20:57
  • Can you update your question with a screenshot of the table config as shown in the AWS console, that shows the primary key? Without seeing that it's hard to be sure that's what your key structure is – andy mccullough Nov 03 '20 at 20:58
  • @MarkMeyer That doesnt seem to the issue, even providing the value "test" results in the same error. – user1698144 Nov 03 '20 at 21:06
  • @MarkMeyer - I have the column type set as a string. See the image on the OP. – user1698144 Nov 03 '20 at 21:11
  • Ah, yes that helps. Have you considered writing your params [the way the example in the docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#getItem-property) does? – Mark Nov 03 '20 at 21:13
  • @MarkMeyer Same result. – user1698144 Nov 03 '20 at 21:22

1 Answers1

0

Try it more like this:

const AWS = require("aws-sdk");

AWS.config.update({ region: "us-west-2" });

const documentClient = new AWS.DynamoDB.DocumentClient();

async function getItem() {
  const params = {
    TableName: "RetailDatabase",
    Key: {
      pk: "jim.bob@somewhere.com",
      sk: "metadata",
    },
  };

  const response = await documentClient.get(params).promise();
  return response;
}

getItem()
  .then((data) =>
    console.log("GetItem succeeded:", JSON.stringify(data, null, 2))
  )
  .catch((error) => console.error(JSON.stringify(error, null, 2)));
NoSQLKnowHow
  • 4,449
  • 23
  • 35