Reputation: 2305
What am i doing wrong here? The following Update call is failing:
await dynamoClient.send(
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: key,
},
UpdateExpression: "set #url = :url, #size = :size, #etag = :etag",
ExpressionAttributeValues: {
":url": { S: publicUrl },
":size": { S: size },
":etag": { S: eTag },
},
ExpressionAttributeNames: {
"#url": "url",
"#size": "size",
"#etag": "etag",
},
ReturnValues: "UPDATED_NEW",
})
);
with the following message:
2022-01-04T07:02:46.912Z 58e4a20d-4631-4d28-b8eb-790be6fd10a9 ERROR Unhandled Promise Rejection {
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: Cannot read property '0' of undefined",
"reason": {
"errorType": "TypeError",
"errorMessage": "Cannot read property '0' of undefined",
"stack": [
"TypeError: Cannot read property '0' of undefined",
" at Object.AttributeValue2.visit (/var/task/index.js:2176:40)",
" at serializeAws_json1_0AttributeValue (/var/task/index.js:7416:40)",
" at /var/task/index.js:7756:18",
" at Array.reduce (<anonymous>)",
" at serializeAws_json1_0Key (/var/task/index.js:7751:36)",
" at serializeAws_json1_0UpdateItemInput (/var/task/index.js:8224:64)",
" at Object.serializeAws_json1_0UpdateItemCommand (/var/task/index.js:3688:29)",
" at serialize (/var/task/index.js:11663:30)",
" at /var/task/index.js:515:29",
" at /var/task/index.js:13099:30"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: TypeError: Cannot read property '0' of undefined",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:400:28)",
" at processPromiseRejections (internal/process/promises.js:245:33)",
" at processTicksAndRejections (internal/process/task_queues.js:96:32)"
]
}
The values are there:
console.log("key, eTag, size, publicUrl:");
console.log(key, eTag, size, publicUrl);
# 2022-01-04T07:02:46.712Z 58e4a20d-4631-4d28-b8eb-790be6fd10a9 INFO images/f796fa32-ed93-451a-b7b6-197b642e25fd/Logo.png af3aaba823d92b492b95695e2545ceda 522215 https://mainstack-imagesgrayhoundbucketimages3b600464-1gabt0s0y3cf0.s3.amazonaws.com/images/f796fa32-ed93-451a-b7b6-197b642e25fd/Logo.png
and here is the dynamodb data in the dynamodb (viewing it as JSON):
{
"path": {
"S": "images/f796fa32-ed93-451a-b7b6-197b642e25fd/Logo.png"
},
"filename": {
"S": "Logo.png"
},
"size": {
"S": ""
},
"userId": {
"S": "f796fa32-ed93-451a-b7b6-197b642e25fd"
},
"meta": {
"M": {
"uploadedDate": {
"S": "2022-01-04T07:19:46.095Z"
}
}
},
"extension": {
"S": "png"
},
"etag": {
"S": ""
},
"url": {
"S": ""
}
}
Upvotes: 1
Views: 687
Reputation: 4034
I believe that here:
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: key,
},
the value passed to path
needs to be an AttributeValue, e.g. { S: key }
, similar to what you've done in ExpressionAttributeValues
.
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: { S: key },
},
Upvotes: 1