Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios always time out on AWS Lambda for a particular API

Tags:

node.js

axios

Describe the issue

I'm not really sure if this is an Axios issue or not. The following code runs successfully on my local development machine but always time out whenever I run it from the cloud (e.g. AWS Lambda). Same thing happens when I run on repl.it.

I can confirm that AWS Lambda has internet access and it works for any other API but this:

https://www.target.com.au/ws-api/v1/target/products/search?category=W95362

Example Code

https://repl.it/repls/AdeptFluidSpreadsheet

const axios = require('axios');

const handler = async () => {
  const url = 'https://www.target.com.au/ws-api/v1/target/products/search?category=W95362';

  const response = await axios.get(url, { timeout: 10000 });

  console.log(response.data.data.productDataList);
}

handler();

Environment

  • Axios Version: 0.19.2
  • Runtime: nodejs12x

Update 1

I tried the native require('https') and it times out on both localhost and cloud server. Please find sample code here: https://repl.it/repls/TerribleViolentVolume

const https = require('https');

const url = 'https://www.target.com.au/ws-api/v1/target/products/search?category=W95362';

https.get(url, res => {
  var body = '';

  res.on('data', chunk => {
    body += chunk;
  });

  res.on('end', () => {
    var response = JSON.parse(body);
    console.log("Got a response: ", response);
  });
}).on('error', e => {
  console.log("Got an error: ", e);
});

Again, I can confirm that same code works on any other API.

Update 2

I suspect that this is something server side as it also behaves very weirdly with curl.

  • curl from local -> 403 access denied
  • curl from local with User-Agent header -> success
  • curl from cloud server -> 403 access denied

It must be server side validation, something related to AkamaiGHost.

like image 871
vab2609 Avatar asked Oct 23 '25 14:10

vab2609


1 Answers

You have probably placed your Lambda function in a VPC without Internet access to the outside world. Try check the VPC section in your lambda configuration, and setup an internet gateway accordingly

like image 60
Chris Yeung Avatar answered Oct 26 '25 05:10

Chris Yeung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!