1

I get data from dynamoDB with Lambda AWS. I try to add parameter to my parameters which I send to Lambda from android app:

if (typeof event.high_lat != "undefined") {
            params.ExpressionAttributeValues = event.high_lat;
        }

But I get an error:

 [InvalidParameterType: Expected params.ExpressionAttributeValues to be a map]
  message: 'Expected params.ExpressionAttributeValues to be a map',

Anyone know how to solve it?

My whole code:

var AWS = require('aws-sdk');
var db = new AWS.DynamoDB();

exports.handler = function(event, context) {


   var params = {
    TableName: "Events", //"StreamsLambdaTable",
    ProjectionExpression: "ID, description, endDate, imagePath, locationLat, locationLon, #nm, startDate, #tp, userLimit",  //specifies the attributes you want in the scan result.
    FilterExpression: "locationLon between :lower_lon and :higher_lon and locationLat between :lower_lat and :higher_lat",
    ExpressionAttributeNames: {
        "#nm": "name",
        "#tp": "type",
    },

     ExclusiveStartKey: {
       "ID": {"S": event.LastEvaluatedKey}
     },

    ExpressionAttributeValues: {
        ":lower_lon": {"N": event.low_lon},
        ":higher_lon": {"N": event.high_lon}, 
        ":lower_lat": {"N": event.low_lat}
    }
};


if (typeof event.high_lat != "undefined") {
            params.ExpressionAttributeValues = event.high_lat;
        }


  db.scan(params, function(err, data) {
    if (err) {
      console.log(err); // an error occurred
      } 
    else {
      data.Items.forEach(function(record) {
           console.log(
                record.name.S + "");
        });
        context.succeed(data.Items);


      }
  });
};

Example of code sent from android app:

{
  "low_lon": "16",
  "high_lon": "17",
  "low_lat": "52",
  "high_lat": "53"
}

1 Answer 1

1

You are blowing away your entire ExpressionAttributeValues map with a single value. You just need to look at the code you wrote above to see how you should add values to the ExpressionAttributeValues map.

Change this:

params.ExpressionAttributeValues = event.high_lat;

To this:

params.ExpressionAttributeValues[":higher_lat"] = {"N": event.high_lat};
Sign up to request clarification or add additional context in comments.

6 Comments

Now i get such an error: { [ValidationException: ExpressionAttributeValues contains invalid key: Syntax error; key: "high_lat"] message: 'ExpressionAttributeValues contains invalid key: Syntax error; key: "high_lat"',
Ah sorry, I missed the syntax slightly. See my updated answer.
Better but now I get: [ValidationException: Invalid FilterExpression: An expression attribute value used in expression is not defined; attribute value: :higher_lat] message: 'Invalid FilterExpression: An expression attribute value used in expression is not defined; attribute value: :higher_lat',
I assume the names like ":lower_lon" and ":higher_lat" aren't actual property names in your table. You need to add the mapping of each name in ExpressionAttributeNames. Add ":high_lat" = "high_lat", ":low_lat" = "low_lat", etc.
I don't even have such properties in my table. My table contains location latitude and longitude. low_lat, high_lat, etc are values (low latitude value, high latitude value) sent from android to find suitable items in DataBase and send them back to android app.
|

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.