I'm running a simple update to add a UUID to an array. It fails with the error message "The update expression attempted to update the secondary index key to unsupported type". But the fields I'm updating are not keys in any secondary indexes.
Here's the update code:
const params = {
"TableName": "churches",
"Key": {
"churchId": "0194fb2a-9a0f-4b6a-b347-7adffbaed8ff",
"countryId": "UK"
},
"ReturnValues": "ALL_NEW",
"UpdateExpression": "set #team = list_append(if_not_exists(#team, :empty_list), :user)",
"ExpressionAttributeNames": {
"#team": "team"
},
"ExpressionAttributeValues": {
":empty_list": [],
":user": [
"b23fe6cf-83e9-417c-b987-e8e645a29bcd"
]
}
}
db.update(params,(err,data) => {
if(err) console.log('ERROR:',err);
if(data) console.log('DATA:',data);
})
The Partition Key is churchId and countryId is the sort key.
And here's the output:
ERROR: { ValidationException: The update expression attempted to update the secondary index key to unsupported type
at Request.extractError (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/protocol/json.js:51:27)
at Request.callListeners (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/request.js:683:14)
at Request.transition (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/state_machine.js:14:12)
at /Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/request.js:685:12)
at Request.callListeners (/Users/richbee/Library/Mobile Documents/com~apple~CloudDocs/code/ec-api/dbcodetest/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
message:
'The update expression attempted to update the secondary index key to unsupported type',
code: 'ValidationException',
time: 2019-09-20T16:51:08.712Z,
requestId: 'IF0CSPBPQLHBAHOBK299V9KGMVVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 400,
retryable: false,
retryDelay: 4.443976966236384 }
These are the secondary indexes configured on the table: screeen shot of secondary indexes
So far, I've asked myself the following questions:
- Am I updating a field that a secondary index uses as a key? - No, the only field I'm updating is 'team', which is a list.
- Am I setting any field values to anything that JS can interpret as anything but a string? - No, it's a UUID
What am I missing?!