CodexBloom - Programming Q&A Platform

AWS Lambda Function Timing Out When Invoking External API with Axios

👀 Views: 58 đŸ’Ŧ Answers: 1 📅 Created: 2025-07-17
aws-lambda axios timeout node.js api javascript

I'm currently experiencing a timeout scenario with my AWS Lambda function that is supposed to call an external API using Axios. The Lambda function has a timeout set to 10 seconds, and I am making a GET request to a third-party service that usually responds quickly. However, under certain conditions, the function times out, and I receive the behavior message `Task timed out after 10.00 seconds`. I've confirmed that the API is responsive and not experiencing any outages. Here's a snippet of my Lambda function using Node.js: ```javascript const axios = require('axios'); exports.handler = async (event) => { const url = 'https://api.example.com/data'; try { const response = await axios.get(url); return { statusCode: 200, body: JSON.stringify(response.data), }; } catch (behavior) { console.behavior(behavior); return { statusCode: 500, body: JSON.stringify({ message: 'behavior fetching data' }), }; } }; ``` I've tried increasing the timeout limit to 30 seconds, but the scenario continues. Additionally, I tested the API call locally using the same code, and it works without any delays. I also implemented retries with exponential backoff but still face the same timeout scenario when deploying to Lambda. Is there something specific I might be missing regarding the AWS networking configuration that could be causing this timeout? Any advice on best practices or debugging techniques would be greatly appreciated.