[英]ENOTFOUND error when call external api endpoint from Lambda
Please provide any suggestions on what needs to be changed with the below code to execute it from Lambda function.请提供有关需要使用以下代码更改的任何建议,以便从 Lambda function 执行它。 It works perfectly fine locally however when executed in Lambda get the following error - {"errno":"ENOTFOUND","code":"ENOTFOUND","syscall":"getaddrinfo","hostname":"https://api.taggun.io"}",
它在本地工作得很好,但是在 Lambda 中执行时会出现以下错误 - {"errno":"ENOTFOUND","code":"ENOTFOUND","syscall":"getaddrinfo","hostname":"https://api .taggun.io"}",
const API_KEY = 'XXxxxxxxxxxxxxxXXX';
/*const fs = require("fs");
const rp = require("request");*/
const https= require('https');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
exports.handler = function(event,context,callback){
var srcBucket = event.Records[0].s3.bucket.name;
var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
var params = {Bucket: srcBucket, Key: srcKey};
var origimage = s3.getObject(params).createReadStream();
const formData = JSON.stringify({
file: {
value: origimage,
}
});
const options = {
hostname: "https://api.taggun.io",
path: "/api/receipt/v1/simple/file",
method: "POST",
headers: {apikey:API_KEY}
};
const req = https.request(options,
(res) => res.on("data", () => callback(null, "OK")));
req.on("error", (error) => callback(JSON.stringify(error)));
req.write(formData);
req.end();
};
One reason it may work locally and not when deployed could be a matter of network connectivity.它可能在本地工作而不是在部署时工作的一个原因可能是网络连接问题。 If the endpoint you are trying to hit is on a private network, you may need to ensure that your lambda is deployed into a vpc subnet which has network connectivity to that private network.
如果您尝试访问的端点位于专用网络上,您可能需要确保将 lambda 部署到与该专用网络具有网络连接的 vpc 子网中。 If that is the case, these docs show the permissions and process for deploying a lambda into a subnet.
如果是这种情况,这些文档显示了将 lambda 部署到子网的权限和过程。
It mean your lambda cannot reach https://api.taggun.io
这意味着您的 lambda 无法到达
https://api.taggun.io
Is your lambda in a VPC?您的 lambda 在 VPC 中吗? Assert it has an internet connection
断言它有互联网连接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.