0
votes

I cant seem to query my dynamodb through lambda. The error message shows: ERROR Unable to scan the table. Error JSON: { "message": "Invalid FilterExpression: An expression attribute value used in expression is not defined; attribute value: :coloursavailable", My code is as follows:

async function dispatch(intentRequest, callback) {
    
const aws = require('aws-sdk');
    aws.config.update({region: 'xxx'});
    var ddb = new aws.DynamoDB();
    var ddbDocClient = new aws.DynamoDB.DocumentClient()
    
    async function getCost(colour,size) {
        var params ={
        TableName : "XXX",
        ProjectionExpression:"Cost",
        FilterExpression: "coloursavailable = :coloursavailable and sizesavailable = :sizesavailable",
        ExpressionAttributeValues:{ ":coloursavailable" : colour,  ":sizesavailable": size}
        }
    return new Promise(resolve =>{
         ddbDocClient.scan(params, onScan)
    
    function onScan(err, data) {
    if (err) {
        console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
    } else {
        data.Items.forEach(function(item) {
           resolve(item.Cost);
        });

    }
}   
    })

    } 

Thanks in advance!

1

1 Answers

0
votes

You can't use the query method on a table without specifying a specific hash key. The method to use instead is scan. So if you replace:

x = tab.query() with

x = tab.scan() I get all the items in my table.