简体   繁体   中英

How can we replace API gateway call with PHP AWS SDK?

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 !

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM