[英]AWS lambda function can't reach the internet
我正在運行一個lambda函數,我想訪問私有數據庫服務器和Internet。 我可以很好地訪問數據庫,但我無法訪問互聯網。
設置:
VPC (10.0.0.0/16)
Public-Subnet (10.0.0.0/24)
NAT-Security-Group (see security groups below)
NAT-Server (AMI NAT instance)
Private-Subnet-1 (10.0.1.0/24) & Private-Subnet-2 (10.0.2.0/24)
DB-Security-Group (see security groups below)
DB-Server (RDS PostgreSQL instance)
Lambda-Security-Group (see security groups below)
Lambda-Function
安全組是:
NAT-Security-Group
Inbound:
HTTP & HTTPS from source: Lambda-Security-Group
SSH from 0.0.0.0/0
Outbound:
All traffic
DB-Security-Group
Inbound:
PostgreSQL from source: Lambda-Security-Group
Outbound:
All traffic
Lambda-Security-Group
Inbound:
HTTP & HTTPS from source: NAT-Security-Group
Outbound:
All traffic
子網的路由表是:
Public-Subnet:
10.0.0.0/16 local
0.0.0.0/0 Internet-Gateway
Private-Subnet-1 & Private-Subnet-2
10.0.0.0/16 local
0.0.0.0/0 NAT-Server
我在這里不知所措。 為什么lambda函數不能到達互聯網(連接超時錯誤)?
您需要在公有子網中創建NAT網關,並通過NAT網關路由來自放置Lambda的子網的出口流量。
要執行此操作,請將NAT網關設置為路由表中的默認網關,該網關連接到放置Lambda的子網。
有關更多詳細信息,請參閱文檔中的Lambda函數的Internet訪問 。
由於您只需要從lambda傳遞數據庫,因此將lambda放入公有子網並且您不需要安裝NAT網關。 無論如何,不會像ELB那樣直接訪問lambda,並且在通過API端點進行任何訪問時必須連接到API網關。
這應該解決從lambda訪問互聯網的問題。 但是,如果您使用EC2中安裝的數據庫以用於將來的補丁管理或來自堡壘主機的任何其他類型的訪問,這只是非常有用。 如果使用RDS,就沒有必要將lambda放在私有子網中。
問題在於安全組的入站/出站規則。 通過上面的配置,我更新了安全組以匹配:
NAT-Security-Group
Inbound:
HTTP & HTTPS from source: Lambda-Security-Group
SSH from source: 0.0.0.0/0
Outbound:
HTTP & HTTPS to destination: 0.0.0.0/0
DB-Security-Group
Inbound:
PostgreSQL from source: Lambda-Security-Group
Outbound:
None
Lambda-Security-Group
Inbound:
None
Outbound:
HTTP & HTTP to destination: NAT-Security-Group
PostgreSQL to source: DB-Security-Group
Lambda功能現在具有互聯網連接功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.