简体   繁体   English

从 Lambda 调用外部 api 端点时出现 ENOTFOUND 错误

[英]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.

相关问题 AWS Lambda:错误:来自api的getaddrinfo ENOTFOUND - AWS Lambda: Error: getaddrinfo ENOTFOUND from api 从 Azure Functions NodeJS 进行 API 调用时 ENOTFOUND - ENOTFOUND when making API call from Azure Functions NodeJS Imgur API调用:443 ENOTFOUND错误疑难解答 - Imgur API call: 443 ENOTFOUND error troubleshooting AWS Lambda 无法调用外部 https 端点 - AWS Lambda unable to call external https endpoint AWS Lambda调用外部API时显示错误 - aws lambda calling external API showing error when it is working 从 aws lambda 调用外部 API 并在 lambda 函数中作为回调获取响应 - call external API from aws lambda and get respose as callback in lambda funtion 使用 Lambda 的 AWS SAM API 端点在使用“sam start local-api”在本地运行时抛出错误 - AWS SAM API endpoint using a Lambda is throwing error when it runs locally with "sam start local-api" 出现错误:getaddrinfo ENOTFOUND 同时执行 rest api 调用 node.js 使用 Z80791B3AE7002FACB888D24 - getting Error: getaddrinfo ENOTFOUND while performing rest api call in node.js using http.request 错误:getaddrinfo ENOTFOUND in nodejs for get call - Error: getaddrinfo ENOTFOUND in nodejs for get call 无法从 AWS lambda(无 VPC)对外部服务进行 API 调用 - Can't make an API call to an external service from AWS lambda (wo VPC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM