I am working on a Google cloud function for beforeSignIn
trigger which needs to fetch some data from a microservice hosted on a AWS Fargate instance. The request times out but only in the Google cloud function environment with this one particular domain. The code runs fine locally.
A simplified version of the code looks like this:
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);
// ...
});
The URL is read in from an environment variable. If I change this environment variable to another domain, like google.com
or bbc.co.uk
, or even a domain pointing to one of our Fargate instances from another project, the fetch works fine in the Google cloud function environment and I get a valid response.
Otherwise the fetch request times out and the cloud function aborts and the following is logged:
Function execution took 20006 ms, finished with status: 'error'
FetchError: request to {url} failed, reason: connect ETIMEDOUT
at ClientRequest.<anonymous> (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
}
According the CloudWatch logs, the request is not reaching the instance. I have checked the network configuration of the AWS environment and couldn't find any obvious problems there.