I have the following code in Lambda that calls an API via Axios that returns a dummy JSON output. This code works perfectly from my local machine, however, when running from Lambda, it always times out when executing the Axios call:
const axios = require('axios');
async function testAxios() {
let result;
console.log("START");
try {
let response = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
result = await response.data;
} catch (errors) {
result = "ERROR: " + errors;
}
console.log("END: " + JSON.stringify(result));
return result;
}
This is the expected output I get when running from my local machine:
START
END: {"userId":1,"id":1,"title":"delectus aut autem","completed":false}
{"statusCode":200,"headers":{"Access-Control-Allow-Origin":"*"},"body":"{"userId":1,"id":1,"title":"delectus aut autem","completed":false}"}
This is the unexpected output I get when running from Lambda where it times out after 10 seconds:
START RequestId: d9ad29e3-858a-47a8-a86d-35fc16704b55 Version: $LATEST
2024-05-08T21:24:00.420Z d9ad29e3-858a-47a8-a86d-35fc16704b55 INFO START
2024-05-08T21:24:10.432Z d9ad29e3-858a-47a8-a86d-35fc16704b55 Task timed out after 10.01 seconds
Other information:
- Nodejs: 18.x
- Axios: 1.6.8
- VPC Inbound/Outbound: All (0.0.0.0/0)
- Lambda timeout: 10 seconds (I’ve tried 30 seconds but get the same results)
Any suggestions to resolve this would be appreciated!