确切的错误如下:
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"message": "1 validation error detected: Value '[object Object]' at 'tableName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z0-9_.-]+",
"code": "ValidationException",
"time": "2019-07-25T05:43:18.119Z",
"requestId": "xxx",
"statusCode": 400,
"retryable": false,
"retryDelay": 42.11544763698385,
"stacktrace": [ ...
我的猜测是,问题出在表的名称上,但是它的名称却是相应的。这是实现:
const putItem = (tableName, newItem) =>
new Promise((resolve, reject) => {
const params = {
TableName: tableName,
Item: newItem,
};
docClient.put(params, (err, data) => {
if (err) {
return reject(err);
}
return resolve(newItem);
});
});
因为我使用的是GraphQL,所以这里是解析器:
const resolvers = {
Mutation: {
createUser: (root, { params }) => {
const tableName = 'Users';
return bcrypt
.hash(params.password, 12)
.then(hashedPassword => {
const newUser = {
_id: uuidv5(params.email, nameSpaces.usersTable),
email: params.email,
password: hashedPassword,
};
return dynamoConnection.putItem(newUser, tableName);
})
.then(result => ({ ...result, password: null }))
.catch(err => {
throw err;
});
},
},
};
如您在最后一个片段中所见,tableName
被定义为Users
,这不应破坏所描述的正则表达式模式。
我不知道下一步该怎么做,尝试了Google搜索,但没有真正可行的结果,其他所有发现都与同一错误无关。
我可以提供什么以调试此错误?
任何帮助,tyvm。