I’m running Node 18 on a Lambda and trying to run fetch(), but still cannot get it to work. No output, no logs, nothing. My timeout is 30 seconds. Any suggestions? Has anyone else gotten it to work?
What NodeJS runtime version are you using? Your runtime might just not have it. It wasn’t fully released until v18. For anything older than 18 you’ll need to use a package like node-fetch to get access to the same API.
Can you verify that you are able to connect to the internet from the Lambda? For example, if you’re deployed in a VPC/subnet without an internet gateway / NAT instance, you may not be able to connect to the public internet.
Can you verify that you’re properly logging errors? Ie is the Lambda permitted to write to cloudwatch? Are you catching the errors (ex .catch(console.error))
I’m also going to add, if you are trying to connect to a public API and your lambda is in a VPC, you need to have a NAT Gateway (and all the configuration needed in a separate subnet with a route table for all traffic 0.0.0.0/0 to the NAT) to access the public internet (Internet gateways doesn’t work for lambda because lambda functions doesn’t have a public IP like EC2).
You’re not catching an error. I think that your lambda is probably running in a public subnet. It must run in a private subnet with a Nat gateway if you are using VPC.. Does it work when not in a vpc?
I’m having the same issue, on a lambda running node 20, and confirmed I have public internet connectivity (not running in a VPC).
I’ve been able to use the `node-fetch` library from an added layer, but am unable to use the native fetch. No errors of undefined fetch, just a timeout.