gpt4 book ai didi

javascript - 使用 AWS Lambda 方法循环访问列表并调用多个其他 lambda 方法

转载 作者:行者123 更新时间:2023-12-03 03:11:18 25 4
gpt4 key购买 nike

我当前正在调用 RDS 数据库来获取项目列表,然后循环这些项目,然后对每个项目进行 POST 调用。我的问题是:

是否可以循环遍历此列表并为列表中的每个项目调用另一个 Lambda 函数。理想情况下,这不会等待响应,而是会继续调用其他人。每个被调用的方法都会继续运行,直到完成。请注意,这是基于 NodeJs 6.10

结构如下:

  var pg = require('knex')({
client: 'pg',
connection: process.env.DATABASE_URL,
debug: true
});

// Internal
const time = require('./lib/time');
const response = require('./lib/response');
const helpers = require('./lib/helpers');

module.exports.createBatch = (event, context, cb) => {

// Lambda settings
context.callbackWaitsForEmptyEventLoop = false;

const now = time.getCurrentTime();

pg('table')
.join('table')
.select('*')

.then(function(rows) {
return rows;
})

.then(function(rows) {
console.log( 'rows: ' + rows );

let count = 0;
if (!_.isEmpty(rows)) {
for(let row of rows) {

// ****
// CALL OTHER LAMBDA FUNCTION HERE
// ****

axios.post(row)
.then(function (res) {

// ****
// MOVE THIS POST CALL INTO ANOTHER LAMBDA FUNCTION
// ****

})

}
}
})

最佳答案

您想要使用适用于 Nodejs 的 AWS 开发工具包来调用 Lambda invoke()功能。传递 InspirationType: Event 参数以异步调用该函数,无需等待响应。

关于javascript - 使用 AWS Lambda 方法循环访问列表并调用多个其他 lambda 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46942208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com