2

I want to execute curl query from one lambda function to another. But I have error in postman:

{"message": "Endpoint request timed out"}

I tried to handle this error. I got this error message:

2019-12-16T09:59:27.830Z 4189c32a-1e9c-4898-a59e-6149c49eaab2 Task timed out after 30.03 seconds

PHP-FPM seems to be running already, this might be because Lambda stopped the bootstrap process but didn't leave us an opportunity to stop PHP-FPM. Stopping PHP-FPM now to restart from a blank slate. Fatal error: Uncaught Bref\Runtime\FastCgi\FastCgiCommunicationFailed: Error communicating with PHP-FPM to read the HTTP response. A root cause of this can be that the Lambda (or PHP) timed out, for example when trying to connect to a remote API or database, if this happens continuously check for those! Original exception message: hollodotme\FastCGI\Exceptions\TimedoutException Read timed out in /var/task/vendor/bref/bref/src/Runtime/PhpFpm.php:126 Stack trace:

0 /opt/bootstrap(30): Bref\Runtime\PhpFpm->proxy(Array)

1 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(92): {closure}(Array, Object(Bref\Context\Context))

2 /opt/bootstrap(34): Bref\Runtime\LambdaRuntime->processNextEvent(Object(Closure))

This is my code:


            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 500,      // timeout on connect
            CURLOPT_TIMEOUT        => 500,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
            CURLOPT_SSL_VERIFYHOST => 0,
            CURLOPT_SSL_VERIFYPEER => 0,
            CURLOPT_USERAGENT      => "",
            CURLOPT_COOKIESESSION  => false,
//            CURLOPT_COOKIEJAR     => $this->ckfile, // Cookies
//            CURLOPT_COOKIEFILE     => $this->ckfile, //Cookies...yum


        );

        //Go go go!
        $ch      = curl_init( $url );
        curl_setopt_array( $ch, $options );

        $output['content'] = curl_exec( $ch );
        $output['err']     = curl_errno( $ch );
        $output['errmsg']  = curl_error( $ch );
        $output['header']  = curl_getinfo( $ch );
        dd($output);

When I use guzzlehttp:


  $client = new \GuzzleHttp\Client();
            $request = $client->get($url);
            $response = $request->getBody();

I get only:

Task timed out after 30.03 seconds

first
  • 482
  • 4
  • 17
  • Could you add more information regarding the functions themselves and have a look at the following - https://stackoverflow.com/questions/53898894/aws-lambda-timeout-when-another-long-lambda-is-invoked – Paul Dawson Dec 16 '19 at 10:42
  • I researched some information and found that Lambda can't connect to anything outside of the VPC. I think this is problem with api gateway. I found tab where I can create VCP links which Provide access to HTTP(S) resources within your Amazon Virtual Private Cloud (VPC). But for now it doesn't work:) – first Dec 16 '19 at 14:04

1 Answers1

1

The problem was in VPC.

Since the lambda function was in the VPC, it could not access external resources.

The simplest solution is to create a lambda funtion without the VPC.

The full answer can be found at this URL:

AWS lambda invoke not calling another lambda function - Node.js

The anwer of johni

first
  • 482
  • 4
  • 17