0

I have being using AWS API Gateway to invoke my AWS Lambda for a while.

My AWS Lambda consist of NodeJS and Express with Backend MongoDB Altas.

I'm facing "Endpoint request timed out" issue in my API calls from PHP Rest Client. Increased the Lamdba timeout to 4 mins and memory to 200 MB as well.

So after doing some research I found out that the AWS API Gateway has a timeout of 30 secs. So to fix this issue I was trying to call my Lambda POST function using AWS SDK.

So far I'm lost with setup and installing and can't find any relevant examples for calling my Lambda directly to invoke the respective Express Endpoints. Below is an example for api function in AWS Lambda

app.post('/api/v1/getback', (req, res) => { res.send({ ...req.body }); });

Not sure if AWS SDK with Express Lambda either.

Can someone help how can we trigger the AWS Lambda using PHP AWS-SDK ? Or any other help would also be appreciated.

Thank you in advance !

Biffen
  • 6,249
  • 6
  • 28
  • 36
Mudassir Khan
  • 318
  • 1
  • 11

1 Answers1

0

Lambda has a client SDK that lets you invoke Lambda functions. There is an example of how to use an API to invoke Lambda here (this is the AWS Java API):

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/lambda/src/main/java/com/example/lambda/LambdaInvoke.java

If you want to use PHP, then you would need to use the AWS SDK for PHP. This Java example should provide you a starting point however.

smac2020
  • 9,637
  • 4
  • 24
  • 38
  • Thanks! @smac2020. I did come across similar PHP example. Working on the implementation part. My only concern is I have to rewrite my Lambda function for SDK invoke as its written to handle http request. – Mudassir Khan Jan 27 '21 at 05:28
  • One more question @smac2020, if I'm using aws-sdk will I be able to do process large data i.e. 2 minutes of processing time ? Currently I'm unable to do the same as API Gateway timeout in restriction. – Mudassir Khan Jan 27 '21 at 12:03
  • 1
    Discussed here - https://stackoverflow.com/questions/31973388/amazon-api-gateway-timeout#:~:text=Timeouts%20can%20be%20decreased%20but,will%20throw%20504%20timeout%20error.&text=While%20you%20cannot%20increase%20the,that%20could%20be%20split%20up. – smac2020 Jan 27 '21 at 13:05