Google Cloud Function调用特定AWS Fargate实例HTTP请求超时问题求助
各位大佬,我最近碰到一个棘手的问题,折腾好久没解决,来求助大家!
我正在开发一个基于Google Cloud Function的beforeSignIn触发器,需要从AWS Fargate上部署的微服务获取数据。这段代码在本地运行完全正常,但一放到Google Cloud Function环境里,针对某一个特定域名的请求就会超时——换成其他域名(比如google.com、bbc.co.uk,甚至我们另一个项目里指向Fargate实例的域名)却能正常拿到响应,简直离谱。
先贴一下简化后的代码:
import { Auth } from 'gcip-cloud-functions'; import fetch from 'node-fetch'; const authClient = new Auth(); export const beforeSignIn = authClient.functions().beforeSignInHandler(async (userRecord, context) => { // ... 其他业务逻辑 const response = await fetch(process.env.MICROSERVICE_URL); // ... 后续数据处理 });
目标域名是从环境变量MICROSERVICE_URL读取的,一旦用这个特定域名,请求就会直接超时,云函数报错终止,日志里的错误信息如下:
Function execution took 20006 ms, finished with status: 'error'
FetchError: request to {url} failed, reason: connect ETIMEDOUT
at ClientRequest.(file:///workspace/node_modules/node-fetch/src/index.js:108:11)
at ClientRequest.emit (node:events:513:28)
at ClientRequest.emit (node:domain:489:12)
at TLSSocket.socketErrorListener (node:_http_client:502:9)
at TLSSocket.emit (node:events:513:28)
at TLSSocket.emit (node:domain:489:12)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
{
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
erroredSysCall: 'connect'
}
我查了AWS那边的CloudWatch日志,发现请求根本没到达Fargate实例。已经把AWS的网络配置(安全组、NACL、路由表这些)都检查了一遍,没发现明显的问题。实在搞不懂为啥只有这个特定域名在GCF环境里连不上,本地和其他域名都正常。
有没有大佬遇到过类似情况?或者能给我一些排查的方向?万分感谢!
备注:内容来源于stack exchange,提问作者alsuvo

