2

I was going to call third party api in the aws lambda function with request. But it shows timeout error. I set the lambda function time 30s and when I call that api by using postman it send response(error) with in 5 seconds. I think the request or axios can't send the request to the external api or can't receive the response. Can anyone help me? My code:

  request.post({url:url2, json:true, body:body, headers: {
    'ACCESS_TIMESTAMP': timestamp,
    'Content-Type': 'application/json'
  } }, (error, response, body) => {
  console.log("------------------I am here----------------------")
  callback(null, error)
})

When I use the axios the code is like below:

let jsonbody = JSON.stringify(body)
axios.post(url2, jsonbody,  {headers: {
      'ACCESS_TIMESTAMP': timestamp,
      'Content-Type': 'application/json'
    }})
.then(res => {
  callback(null, res.data)
})
.catch(err => {
  callback(null, err)
})

I want to get the result of res or err but they don't act.

1
  • Is your lambda running inside vpc? Commented Aug 1, 2020 at 3:05

1 Answer 1

5

When you locate the Lambda into your VPC with the private subnet, then you have to set the NAT gateway into your private subnet. If you didn't connect the NAT, Lambda cannot connect to the public internet and can communicate with the private IPs only.

Sign up to request clarification or add additional context in comments.

1 Comment

I get a similar issue but am invoking the function locally, so it shouldn't be anything networking or VPC related right (first time writing an aws lambda - go easy)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.