dynamodb 更新调用因非描述性错误而失败
dynamodb update call failing with non descriptive error
我在这里做错了什么?
以下更新调用失败:
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",
})
);
带有以下消息:
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)"
]
}
值在那里:
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
这是 dynamodb 中的 dynamodb 数据(将其视为 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": ""
}
}
我相信这里:
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: key,
},
传递给 path
的值需要是 AttributeValue,例如{ S: key }
,类似于您在 ExpressionAttributeValues
中所做的。
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: { S: key },
},
我在这里做错了什么? 以下更新调用失败:
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",
})
);
带有以下消息:
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)"
]
}
值在那里:
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
这是 dynamodb 中的 dynamodb 数据(将其视为 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": ""
}
}
我相信这里:
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: key,
},
传递给 path
的值需要是 AttributeValue,例如{ S: key }
,类似于您在 ExpressionAttributeValues
中所做的。
new UpdateItemCommand({
TableName: IMAGE_TABLE_NAME,
Key: {
path: { S: key },
},