这是我的场景:
上运行的SQL查询。
中生成结果
获取S3文件位置。
中创建的爬虫的Lambda

要在Lambda中创建AWS爬虫,下面是我在Lambda (NodeJS)中的代码:
exports.handler = async(event) => {
const awsglue = new aws.Glue();
const uuid = event.QueryExecutionID
var path = event.OutputPath
var params = {
Name: uuid,
Role: <Role ARN>,
DatabaseName: <Database name>,
Targets: {
S3Targets: [{
Path: path
}]
}
}
var request = await awsglue.createCrawler(params, (err, data) => {
if (err) console.log(err, err.stack);
else console.log(data);
})
const response = {
statusCode: 200,
body: JSON.stringify(uuid),
};
return response;
};Problem createCrawler是一个异步调用,Lambda甚至在创建爬虫之前就返回成功。因此,用于运行爬虫的Task-3失败了。
为了解决这个问题,我尝试将createCrawler和startCrawler合并到同一个Lambda函数中,但这也不起作用。
我是不是遗漏了什么?不可能在由Step函数触发的Lambda函数中创建AWS Glue爬虫吗?
发布于 2021-08-15 15:39:04
Glue爬虫应该以Infra管理的Step函数的状态机作为代码创建,比如CloudFormation、Terraform和AWS。
然后,lambda函数启动爬虫并检索爬虫运行的结果。
参见类似的示例代码,
https://stackoverflow.com/questions/68780866
复制相似问题