Reputation: 15
I'm trying to make a very simple getitem request to DynamoDb from lambda, but I'm not getting back any results.
Yes, I checked the permissions and they made sure that they are granted for lambda execution and dynamodb getitem functions for the appropriate table and that they are correctly attached to the lambda function.
Yes, there is definitely an entry in that table with name: "Bobas".
Here is what I'm getting from console.logs :
START RequestId: 1db3eebb-8edb-4bfa-987d-4afc9831c7b6 Version: $LATEST
END RequestId: 1db3eebb-8edb-4bfa-987d-4afc9831c7b6
REPORT RequestId: 1db3eebb-8edb-4bfa-987d-4afc9831c7b6 Duration: 680.59 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 91 MB Init Duration: 366.03 ms
Code follows:
const AWS = require('aws-sdk');
AWS.config.update({ region: 'ca-central-1'});
exports.handler = async (event, context, callback) => {
let resp;
// TODO implement
const ddb = new AWS.DynamoDB({ apiVersion: '2012-10-08'});
const params = {
TableName: 'trivia-users',
Key: {
name: {
S: 'Bobas'
}
}
}
ddb.getItem(params, (err, data) => {
let resp = data;
if (err) {
console.log(err);
} else {
console.log(data);
}
});
return resp;
};
Upvotes: 0
Views: 79
Reputation: 2580
You have to either make it non-async or return a promise back to the caller (you can return that promise directly to the runtime). Like this:
const AWS = require('aws-sdk');
AWS.config.update({ region: 'ca-central-1'});
exports.handler = async (event, context, callback) => {
const ddb = new AWS.DynamoDB({ apiVersion: '2012-10-08'});
const params = {
TableName: 'trivia-users',
Key: {
name: {
S: 'Bobas'
}
}
}
return ddb.getItem(params, null).promise();
};
Upvotes: 1