I'm just getting started using DynamoDB and have setup an 'accounts' table.
I've set-up a secondary index so I can query an api user and user key. Neither of these values are the primary key, as they are both volatile and can be changed.
The Table is built with
TableName: "Accounts",
KeySchema: [
{ AttributeName: "id", KeyType: "HASH" },
{ AttributeName: "email", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "id", AttributeType: "S" },
{ AttributeName: "email", AttributeType: "S" }
]
And the Index is
TableName: 'Accounts',
AttributeDefinitions: [
{AttributeName: 'name', AttributeType: 'S'},
{AttributeName: 'apiKey', AttributeType: 'S'}
],
GlobalSecondaryIndexUpdates: [
{
Create: {
IndexName: "ApiAccounts",
ProvisionedThroughput: {
ReadCapacityUnits: 1, WriteCapacityUnits: 1
},
KeySchema: [
{AttributeName: 'name', KeyType: "HASH"},
{AttributeName: 'apiKey', KeyType: "STRING"}
],
Projection: {
ProjectionType: "KEYS_ONLY"
},
I'm now trying to get a uses account by querying the ApiAccounts
index.
I'm trying
dynamoClient.get({
TableName: 'Accounts',
IndexName: 'ApiAccounts',
Key: {
name: nameKeyArray[0],
apiKey: nameKeyArray[1]
}, callback)
But I am getting an error One of the required keys was not given a value
, which leads me to believe I can't do a 'get' on a Index? Or I'm not referring the index properly. Can somebody clarify for me?
Name and API Key are unique, so I think I want to avoid a query or scan if possible