2
votes

I am using AWS Console and NodeJS.

I have the dynamodb table of users with partition key (user_id) and sort key (company_id) and other attributes.

One of my attributes is email of user. Email is unique attribute.

I need to get user_id by email but I haven't his user_id and company_id.

I think that I should use a Global Secondary Index.

I clicked on the users table, opened the Indexes tab and created GSI for this table. (name: email, type: GSI, Partition Key: email string, attributes: user_id)

I am using method Query from documentClient. This is my payload:

payload = {
    "TableName": "users",
    "IndexName": "email",
    "KeyConditionExpression": "#index = :index_value",
    "ExpressionAttributeNames":{
        "#index": "email"
    },
    "ExpressionAttributeValues": {
        ":index_value": {"S": "[email protected]"}
    },
    "ProjectionExpression": "user_id",
        "ScanIndexForward": false
    };
}

This is my error from CloudWatch:

"errorMessage": "One or more parameter values were invalid: Condition parameter type does not match schema type"

1

1 Answers

0
votes

I have found a solution while I was writing this question. So as I use documentClient my payload should looks like this

payload = {
    "TableName": "users",
    "IndexName": "email",
    "KeyConditionExpression": "#index = :index_value",
    "ExpressionAttributeNames":{
        "#index": "email"
    },
    "ExpressionAttributeValues": {
        ":index_value": "[email protected]" // <----------------
    },
    "ProjectionExpression": "user_id",
        "ScanIndexForward": false
    };
}

Hope it helps to someone