I am using Amplify to setup a dynamodb with a corresponding lambda using the amplify blueprint for dynamodb.
Accessing the dynamodb the "classic" way with KeyConditionExpression etc works just fine but today I wanted to try and use PartiQL instead with the executeStatement and I am just not able to get it to work.
I have added the "dynamodb:PartiQLSelect" permission to the cloudfront template where all the other dynamodb permissions are so it looks like:
"Action": [
"dynamodb:DescribeTable",
"dynamodb:GetItem",
"dynamodb:Query",
"dynamodb:Scan",
"dynamodb:PutItem",
"dynamodb:UpdateItem",
"dynamodb:DeleteItem",
"dynamodb:PartiQLSelect"
],
and I do not get any permission error so I hope that part is ok, it does however return the same error even without that line added.
The error that is always returned is: ValidationException: Unexpected from source"
and no matter what I have tried, it does not help. My code is quite basic so far:
const dynamodb2 = new AWS.DynamoDB();
let tableName = "habits_sensors";
if(process.env.ENV && process.env.ENV !== "NONE") {
tableName = tableName + '-' + process.env.ENV;
}
app.get(path, function(req, res) {
let params = {
Statement: `select * from ${tableName}`
};
dynamodb2.executeStatement(params, (err, data) => {
if (err) {
res.statusCode = 500;
res.json({error: `Could not get users from : ${tableName} =>` + err});
} else {
res.json(data.Items);
}
});
});
The complete error string returned from the lambda is:
{
"error": "Could not get users from : habits_sensors-playground =>ValidationException: Unexpected from source"
}
and I have the table habits_sensors-playground in my AWS account and I can access it the classic way without problems. That is why the "Unexpected from source" is confusing. I interpret it as referring to that the tableName (in from) in the select query is not correct but the name is matching what I have in AWS and it works using the documentclient.
Any suggestion on what might be wrong is very appreciated.