0

I've created an API in API Gateway which calls a lambda function to query my RDS database and return the query results as JSON. I'm trying to call my api from JavaScript using the following code but all I'm getting in the console of the browser is 'GET https://myurl/v1/it-requests net::ERR_TIMED_OUT'. But when I run call the API from the URL it returns the query result? My JavaScript is below.

var apigClient = apigClientFactory.newClient({
    apiKey: 'myApiKey',
  });

var params = {
};
  
var body = {
};

apigClient.itRequestsGet(params, body)
  .then(function(result){
      console.log = JSON.stringify(result);
  }).catch(function(result){
      console.log = "Sorry, API Gateway is not responding";
  });
<script type="text/javascript" src="lib/axios/dist/axios.standalone.js"></script>
<script type="text/javascript" src="lib/CryptoJS/rollups/hmac-sha256.js"></script>
<script type="text/javascript" src="lib/CryptoJS/rollups/sha256.js"></script>
<script type="text/javascript" src="lib/CryptoJS/components/hmac.js"></script>
<script type="text/javascript" src="lib/CryptoJS/components/enc-base64.js"></script>
<script type="text/javascript" src="lib/url-template/url-template.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/sigV4Client.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/apiGatewayClient.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/simpleHttpClient.js"></script>
<script type="text/javascript" src="lib/apiGatewayCore/utils.js"></script>
<script type="text/javascript" src="apigClient.js"></script>
Delowar Hosain
  • 2,214
  • 4
  • 18
  • 35
Matt M
  • 375
  • 1
  • 5
  • 14

1 Answers1

0

Browser's have default timeouts see this you can return 202 initially and keep the connection alive while u r doing stuff, then once your processing is done end the connection.

for example:

res.status(200);
res.type('application/json');

res.write(' ');
res.flush();
const writeInterval = setInterval(() => {
  res.write(' ');
  res.flush();
}, 15000);

After processing is done:

  res.end(JSON.stringify({
    success: 1
    //blah...
  }));
3960278
  • 756
  • 4
  • 12