需要在parms中使用nextToken传递给下一次调用getExecutionHistory。您可以递归调用此函数,直到所有令牌都用完为止。通过Cloud watch获取日志时遇到类似情况。
递归获取历史记录的示例,
将getExecutionHistory包装到promise中并添加到不同的JS文件(比如说writer.js)然后你的主index.js文件可以像这样调用那个函数,
// writer.js which writes record to Dynamodb
// returns promise
// when history is fetched , dynamodb will be inserted and it will resolve dataexecution which has nextToken
module.exports.get = function(fwdtoken) {
if (fwdtoken) parms.nextToken= fwdtoken;
return new Promise ( (resolve, reject)=>{
stepfunctions.getExecutionHistory(params, function(err, dataExecution) {
if (err){
reject(err.stack)
}
else {
const params2 = {
TableName: table,
Item: {
id: executionARN,
execution_history: dataExecution
}
};
dynamoDb.put(params2).promise();
resolve(dataExecution)
}
});
})
};
//This goes in main logic
// Invokes getAllLogs recursilvely
var writer = require(‘./writer’);
var fwdtoken;
function getAllLogs(fwdtoken, fetchCount) {
fetchCount = fetchCount || 0;
if (fetchCount > 40) {
throw new Error(“Fetched too many times.”);
}
return new Promise( (resolve) => {
writer.get(fwdtoken).then( function consolidate( dataExecution ) {
resolve( dataExecution );
});
})
.then(function ( dataExecution ) {
if (dataExecution.nextForwardToken) {
fwdtoken = dataExecution.nextForwardToken;
getAllLogs(fwdtoken, fetchCount+ 1)
}
else
return fwdtoken
});
}
getAllLogs(fwdtoken, 0);
</code>