为什么使用更新表达式更新 DynamoDB 项目会导致 500 InternalFailure 和 30 秒挂起?
Why does a DynamoDB item update with an update expression cause a 500 InternalFailure & a 30 second hang?
我在尝试使用 Node.js AWS SDK (AWS.DynamoDB.DocumentClient
) 使用 UpdateExpression
执行更新时收到 500 Internal Error
。
操作挂起大约 30 秒,然后 returns 此错误:
InternalFailure: null
at Request.extractError (WORKSPACE/node_modules/aws-sdk/lib/protocol/json.js:52:27)
at Request.callListeners (WORKSPACE/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (WORKSPACE/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (WORKSPACE/node_modules/aws-sdk/lib/request.js:688:14)
at Request.transition (WORKSPACE/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (WORKSPACE/node_modules/aws-sdk/lib/state_machine.js:14:12)
at WORKSPACE/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (WORKSPACE/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (WORKSPACE/node_modules/aws-sdk/lib/request.js:690:12)
at Request.callListeners (WORKSPACE/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 'InternalFailure',
time: 2021-10-08T16:24:49.756Z,
requestId: 'EJJH7IIRFCS0HOPNQ9IIS39CKJVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 500,
retryable: true
}
我在 运行 我在 Lambda 函数中的代码以及 运行 在本地使用 DynamoDB REST API 时都得到了这个(所以这不是 Lambda 权限问题)。
导致此内部错误的原因是什么?
我更新项目的代码:
export async function addOverride(addOverrideRequest: any) {
const addListIfNotExists = {
TableName: addOverrideRequest.table,
Key: {
Environment: addOverrideRequest.environment
},
UpdateExpression: "SET Overrides.:overrideAttr = :emptylist",
ConditionExpression: "attribute_not_exists(Overrides.:overrideAttr)",
ExpressionAttributeValues: {
":overrideAttr": addOverrideRequest.overrideField,
":emptylist": [],
},
}
try {
const result = await DOCUMENT_CLIENT.update(addListIfNotExists).promise();
} catch (error) {
throw error;
}
}
请求解析为:
{
TableName: 'AppVersions',
Key: { Environment: 'int' },
UpdateExpression: 'SET Overrides.:overrideAttr = :emptylist',
ConditionExpression: 'attribute_not_exists(Overrides.:overrideAttr)',
ExpressionAttributeValues: { ':overrideAttr': 'EyeTrackerType', ':emptylist': [] }
}
使用 ExpressionAttributeNames
定义您的属性名称,而不是将它们添加到 ExpressionAttributeValues
。
ExpressionAttributeNames 用于指定动态属性名称,但是,您在 [=24] 中指定 overrideAttr
=]表达式属性值.
此外,您必须使用井号 - #
- 来指示属性名称的占位符。
这应该有效:
const addListIfNotExists = {
TableName: addOverrideRequest.table,
Key: {
Environment: addOverrideRequest.environment
},
UpdateExpression: "SET Overrides.#overrideAttr = :emptylist",
ConditionExpression: "attribute_not_exists(Overrides.#overrideAttr)",
ExpressionAttributeNames: {
"#overrideAttr": addOverrideRequest.overrideField
},
ExpressionAttributeValues: {
":emptylist": []
},
}
我在尝试使用 Node.js AWS SDK (AWS.DynamoDB.DocumentClient
) 使用 UpdateExpression
执行更新时收到 500 Internal Error
。
操作挂起大约 30 秒,然后 returns 此错误:
InternalFailure: null
at Request.extractError (WORKSPACE/node_modules/aws-sdk/lib/protocol/json.js:52:27)
at Request.callListeners (WORKSPACE/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
at Request.emit (WORKSPACE/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (WORKSPACE/node_modules/aws-sdk/lib/request.js:688:14)
at Request.transition (WORKSPACE/node_modules/aws-sdk/lib/request.js:22:10)
at AcceptorStateMachine.runTo (WORKSPACE/node_modules/aws-sdk/lib/state_machine.js:14:12)
at WORKSPACE/node_modules/aws-sdk/lib/state_machine.js:26:10
at Request.<anonymous> (WORKSPACE/node_modules/aws-sdk/lib/request.js:38:9)
at Request.<anonymous> (WORKSPACE/node_modules/aws-sdk/lib/request.js:690:12)
at Request.callListeners (WORKSPACE/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
code: 'InternalFailure',
time: 2021-10-08T16:24:49.756Z,
requestId: 'EJJH7IIRFCS0HOPNQ9IIS39CKJVV4KQNSO5AEMVJF66Q9ASUAAJG',
statusCode: 500,
retryable: true
}
我在 运行 我在 Lambda 函数中的代码以及 运行 在本地使用 DynamoDB REST API 时都得到了这个(所以这不是 Lambda 权限问题)。
导致此内部错误的原因是什么?
我更新项目的代码:
export async function addOverride(addOverrideRequest: any) {
const addListIfNotExists = {
TableName: addOverrideRequest.table,
Key: {
Environment: addOverrideRequest.environment
},
UpdateExpression: "SET Overrides.:overrideAttr = :emptylist",
ConditionExpression: "attribute_not_exists(Overrides.:overrideAttr)",
ExpressionAttributeValues: {
":overrideAttr": addOverrideRequest.overrideField,
":emptylist": [],
},
}
try {
const result = await DOCUMENT_CLIENT.update(addListIfNotExists).promise();
} catch (error) {
throw error;
}
}
请求解析为:
{
TableName: 'AppVersions',
Key: { Environment: 'int' },
UpdateExpression: 'SET Overrides.:overrideAttr = :emptylist',
ConditionExpression: 'attribute_not_exists(Overrides.:overrideAttr)',
ExpressionAttributeValues: { ':overrideAttr': 'EyeTrackerType', ':emptylist': [] }
}
使用 ExpressionAttributeNames
定义您的属性名称,而不是将它们添加到 ExpressionAttributeValues
。
ExpressionAttributeNames 用于指定动态属性名称,但是,您在 [=24] 中指定 overrideAttr
=]表达式属性值.
此外,您必须使用井号 - #
- 来指示属性名称的占位符。
这应该有效:
const addListIfNotExists = {
TableName: addOverrideRequest.table,
Key: {
Environment: addOverrideRequest.environment
},
UpdateExpression: "SET Overrides.#overrideAttr = :emptylist",
ConditionExpression: "attribute_not_exists(Overrides.#overrideAttr)",
ExpressionAttributeNames: {
"#overrideAttr": addOverrideRequest.overrideField
},
ExpressionAttributeValues: {
":emptylist": []
},
}