0

I am attempting to query a string set item from DynamoDB

Error :

{
    "errorMessage":"{
        "message": "Unexpected key 'Key' found in params",
        "code": "UnexpectedParameter",
        "time": "2016-01-06T08:24:02.183Z"
    }"
}

Code :

var table = 'users'
var params = {
    TableName : table,
    Key : {
        'userType': { 'S': event.type },
        'username': { 'S': event.username }
    }
}

ddb.query (params, function(err, data) {
    if (err) {
        // Oh well
    } else {
        context.succeed (data.Item)
    }
})

I want my system to allow multiple users to have the same username - sounds silly, its for a good reason.

Thank you in advance

1 Answer 1

2

Get Item

  • Requires : TableName, Key (at least hash)
  • Optional : AttributesToGet, ConsistentRead, ExpressionAttributeNames, etc.

If you change ddb.query to ddb.getItem - that code should work perfectly.

So your getItem product would look like:

var table = 'users'
var params = {
    TableName : table,
    Key : {
        'userType': { S: event.type },
        'username': { S: event.username }
    }
}

ddb.getItem (params, function(err, data) {
    if (err) {
        // Oh well
    } else {
        context.succeed (data.Item)
    }
})

You will probably want Query though, that way you can return multiple items

Query

  • Requires : TableName, (KeyConditionExpression && ExpressionAttributeValues) || KeyConditions
  • Optional : ReturnConsumedCapacity, QueryFilter, ProjectionExpression, Limit, etc.

This would be:

var table = 'usatUsers'
var params = {
    TableName : table,
    KeyConditions: {
        "userType": {
            "AttributeValueList": [{
                S: event.type
            }],
            "ComparisonOperator" : "EQ"
        }
    }
}

ddb.query (params, function(err, data) {
    if (err) {
        // Oh well
    } else {
        context.succeed (data)
    }
})

Also, be careful of reserved keys CHECK THIS LIST to make sure all your names are compliant

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.