AWS Lambda连接到Internet

编程入门 行业动态 更新时间:2024-10-28 08:27:15
本文介绍了AWS Lambda连接到Internet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从AWS Lambda连接到互联网,我有一个带有NAT网关的私有子网,但该功能仍然无法连接到互联网。 ..

I am trying to connect to internet from AWS Lambda, I have a private subnet with a NAT Gateway but still the function cannot connect to internet...

所以我尝试使用我的AWS Lambda函数访问互联网。我已经尝试了Java和NodeJS 4而没有运气。

So I am trying to access internet with my AWS Lambda function. I have tried both Java and NodeJS 4 with no luck.

我有一个带子网的私有VPC:10.0.10.0/24

I have a private VPC with a subnet: 10.0.10.0/24

如您所见,我已将规则添加到我的NAT网关:

As you can see I have added a rule to my NAT Gateway:

我将AWS Lambda配置为:

I configured my AWS Lambda like this:

选择该子网(10.0.10.0)并使用对所有事物都开放的安全组(入站和出站)

Selecting that subnet (10.0.10.0) and with a security group that is open to everything (both inbound and outbound)

但是当我尝试从互联网上下载内容时,lambda次out:

But yet when I try to download something from internet, the lambda times out:

'use strict'; console.log('Loading function'); var http = require("http"); exports.handler = (event, context, callback) => { //console.log('Received event:', JSON.stringify(event, null, 2)); console.log('value1 =', event.key1); console.log('value2 =', event.key2); console.log('value3 =', event.key3); var options = { host: 'www.virgilio.it', port: 80, path: '/' }; http.get(options, function(res) { console.log("Got response: " + res.statusCode); }).on('error', function(e) { console.log("Got error: " + e.message); }); callback(null, event.key1); // Echo back the first key value // callback('Something went wrong'); };

{errorMessage:2016-05- 10T10:11:46.936Z 79968883-1697-11e6-9e17-1f46a366f324任务在55.00 秒后超时}

{ "errorMessage": "2016-05-10T10:11:46.936Z 79968883-1697-11e6-9e17-1f46a366f324 Task timed out after 55.00 seconds" }

这是一个错误吗?

注意:相同的功能有效如果我没有选择我的VPC

推荐答案

我发现错误,应该将NAT网关添加到公有子网(不是私有子网)。 A公有子网是与 0.0.0.0/0相关联的Internet Gatway路由的子网

I found the error, the NAT Gateway should be added to a public subnet (not a private one). A public subnet is the subnet with the Internet Gatway route associated to 0.0.0.0/0

更多推荐

AWS Lambda连接到Internet

本文发布于:2023-11-15 16:29:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   AWS   Lambda   Internet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!