0

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 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.