The following code produces this error message when trying to access my AWS DynamoDB table. The table is called customers and the column is called email with a value of '[email protected]'. I've copied this code straight out of AWS examples available here https://github.com/awsdocs/aws-doc-sdk-examples. Is there anything I'm doing wrong? I've wasted days on this, trying different things :-(
Any help appreciated. Thanks,
Error message
{"message":"Expected params.Key to be a map","code":"InvalidParameterType","time":"2019-03-13T23:05:59.231Z"}
NodeJs code
const express = require('express')
const app = express()
const port = 8080
var AWS = require('aws-sdk');
app.get('/test', (req, res) => {
// Set the region
AWS.config.update({region: 'eu-west-1'});
// Create DynamoDB document client
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var key = { email: '[email protected]' };
ddb.getItem({
TableName: 'customers',
Key: key
}, function(err, data) {
if (err) {
res.send(err);
}
else {
res.send(data);
}
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
DynamoDB table
Another attempt I've also received this error message
{"message":"There were 20 validation errors:\n* InvalidParameterType: Expected params.Key['email'] to be a structure\n* UnexpectedParameter: Unexpected key '0' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '1' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '2' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '3' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '4' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '5' found in params.Key['email']\n* UnexpectedParameter: Unexpected key '6' found in
Update
var key = { email: '[email protected]' };
ddb.getItem({
TableName: 'customers',
Key: key
}, function(err, data) {
if (err) {
res.send(err);
}
else {
res.send(data);
}
});
Update
const express = require('express')
const app = express()
const port = 8080
var AWS = require('aws-sdk');
app.get('/test', (req, res) => {
AWS.config.update({region: 'eu-west-1'});
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
TableName: 'customers',
Key: {
'email': {S: '[email protected]'}
},
};
ddb.getItem(params, function(err, data) {
if (err) {
res.send(err);
} else {
res.send(data);
}
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Error result
{"message":"The provided key element does not match the schema","code":"ValidationException","time":"2019-03-14T19:26:13.602Z","requestId":"EIGKLLNEJR2DKSET6787JHQLC7VV4KQNSO5AEMVJF66Q9ASUAAJG","statusCode":400,"retryable":false,"retryDelay":46.10177725769697}

