Hello, I have just created a website for myself. I also created a couple of netlify functions.
In one of my functions, I need to send an HTTP request to an external server to get data. However, I am not able to accomplish this task as my HTTP request times out every time.
Is this an intentional thing? Or is there a way to send HTTP requests inside a netlify function and I don’t know how to configure it?
Could you show us the code? Netlify functions run for 10 seconds before they are forcefully terminated (I think it’s 10 seconds), if your request takes longer then that then Netlify terminates it.
@freddy I am trying to access to a file in S3. I am sure that I set up my S3 connection correctly. I tested the same code in my computer and it worked. But when I deployed that code to a netlify function, it timed out.
This is my code that I use to connect and get a file from S3:
@freddy Thanks for pointing that out. I am going to fix it. I just put a couple of console.log statements to see what is going on. It seems like the code is able to get the file from S3 and read its contents. But when I tested by sending a request to this function, no response comes and it times out. Although, the logging shows that everything went fine.
It seems like the header that I added content-length is making this whole thing fail. I didn’t clearly understand why but as soon as I removed this header from my response, I am able to get a correct response.
content.length refers to the string length, not the octet length, you would need to use something like Buffer.byteLength(content) to set the header correctly.