DynamoDB DocumentClient.put意外返回DynamoDB.putItem错误



我正在使用Dynamo DB和Node JS,并且我的put方法收到了没有任何意义的错误。

我几乎是随机地收到一个错误,DocumentClient.put期望对象与DynamoDB.putItem方法匹配,从而产生了这个错误(这是一个例子,但我收到的每个字段都有一个错误(:

InvalidParameterType: Expected params.Item['startDateTime'] to be a structure","

以下是我的对象的样子:

payload: {
TableName: TABLE, 
Item: {
gameId: 3534422,
awayhome: 'ATLMIN',
startDateTime: '2020-10-18T17:00:00Z',
location: 'Minneapolis, Minnesota',
stadium: 'U.S. Bank Stadium',
sport: 'nfl',
year: 2020,
season: 'Regular',
awayTeam: { 
fullName: 'Atlanta Falcons',
shortName: 'Falcons',
code: 'ATL' 
},
homeTeam: {
fullName: 'Minnesota Vikings',
shortName: 'Vikings',
code: 'MIN'
},
gameStatus: 'Unplayed' 
} 
}

这是我从Lambda到DynamoDB的看跌期权:

db.put(payload, function(err,data) {
if (err) {
console.log('update error: ', err);
callback(err, null);
}
if (data) {
console.log({ successfulUpdate: data });
}
})

奇怪的是,它的发生似乎没有任何明确的原因。我会对我的Lambda函数进行一个小的更改,有时根本不更改对象或DynamoDB调用,并且会收到错误。

我真的不明白这是如何解决问题的,但我最终做的是这样。

我用一种不同的方法创建有效负载,并直接使用该输出。

相反,我这样重新组装:

const { gameId,
awayhome,
status,
startDateTime,
location,
stadium,
sport,
year,
season,
homeTeam,
awayTeam
} = payload.Item
payload.Item = {
gameId,
awayhome,
status,
startDateTime,
location,
stadium,
sport,
year,
season,
homeTeam: {...homeTeam},
awayTeam: {...awayTeam},
odds: {
spread: odds.spread,
total: odds.total,
history: odds.history,
prices: odds.prices
}
}

我添加了一些有效载荷,直到它工作为止。我猜可能有一些不正确的属性或其他什么。

最新更新