You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过AWS RDS与Lambda抓取数据时遇连接超时错误,求排查方向

Troubleshooting Lambda Connection Timeout to news.google.com

First, let's restate the error you're seeing for clarity:

"errorMessage": "HTTPSConnectionPool(host='news.google.com', port=443): Max retries exceeded with url: /news/headlines?hl=tr&gl=TR&ned=tr_tr (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 110] Connection timed out',))"

This timeout means your Lambda function can't establish an outbound HTTPS connection to Google News. Below are the most common causes and how to diagnose/fix them:

1. Lambda is in a VPC Without Internet Access

Since you're using AWS RDS, it's almost certain your Lambda is deployed in a VPC (to connect to RDS privately). By default, Lambda functions in a VPC don't have internet access unless you set up a NAT Gateway or NAT Instance:

  • Check Lambda's VPC setup: Go to the Lambda console → Configuration → VPC. If it's associated with a VPC/subnet, proceed.
  • Verify subnet routing: The subnet your Lambda uses must have a route table entry pointing to a NAT Gateway (not an internet gateway—internet gateways only work for resources with public IPs, which Lambda doesn't get by default).
  • NAT Gateway placement: The NAT Gateway needs to be in a public subnet with an internet gateway attached to it.

2. Security Group or Network ACL Restrictions

Your Lambda's network security rules might be blocking outbound HTTPS traffic:

  • Lambda Security Group: Go to Lambda → Configuration → VPC → Security groups. Ensure there's an outbound rule allowing traffic to 0.0.0.0/0 (or the specific IP ranges for news.google.com) on port 443 (HTTPS).
  • Network ACLs: If your VPC/subnet uses Network ACLs (stateless firewalls), make sure they allow:
    • Outbound traffic on port 443 to 0.0.0.0/0
    • Inbound traffic on ephemeral ports (typically 1024-65535) from 0.0.0.0/0 (since responses from Google need explicit permission)

3. DNS Resolution Failures

If your Lambda is in a VPC, incorrect DNS settings can prevent it from resolving news.google.com to an IP address:

  • VPC DNS Settings: Go to your VPC console → Select your VPC → Check that "DNS hostnames" and "DNS resolution" are both set to Yes.
  • Test DNS: Launch an EC2 instance in the same subnet as your Lambda, then run nslookup news.google.com to confirm the domain resolves correctly. If it doesn't, you might need to adjust your VPC's DNS server settings.

4. Google's IP Blocking (Less Common)

Occasionally, Google might block AWS IP ranges (since they're often used for scraping). To rule this out:

  • Modify your Lambda to test a different external HTTPS site (like https://example.com). If that works, the issue is specific to Google News.
  • If so, you could try using a proxy service or rotating your outbound IP (via multiple NAT Gateways), but first confirm it's not a VPC/security group issue.

5. RDS Configuration Conflicts (Unlikely)

Double-check that your RDS setup isn't interfering with Lambda's outbound access:

  • Ensure the route table for your Lambda's subnet still includes the NAT Gateway route (sometimes people accidentally remove it when configuring RDS access).
  • The RDS security group only needs inbound access from your Lambda's security group—outbound traffic from Lambda isn't affected by RDS's rules.

内容的提问来源于stack exchange,提问作者Oğuz Kırçicek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 08:58:17