aws lambda - 503 service unavailable when calling 3rd party API using axios

Viewed 108

I have a lambda function which is calling 3rd party API using axios, when it calls 3rd party API, it creates a new entry on their database, which is working fine but the lambda function is returning 503 service unavailable

Following is my code -

let algcon = {
    method: 'post',
    url: constants.API_URL,
    timeout: 1000 * 7,
    headers: {
        'Content-Type': 'application/json',
        "User-Agent": "axios 0.21.1",
        'token': myToken ? JSON.stringify(myToken.access) : ''
    },
    data: invoiceData,
};

await axios(algcon).then(function (response) {

}).catch(function (error) {
    console.log(error) //here it is throwing 503 service unavailable error    
});

I have increased lambda execution time but still getting the same error. Please help!!

1 Answers

Your code looks fine to me,

the default timeout of an API gateway response is 6500 milliseconds

You can update it as -

  1. Go to API gateway
  2. Select Lamda function
  3. Click on integration
  4. Click on Manage integration
  5. Update default timeout

Like I did in below screenshot -

enter image description here

Related