Bref: Serverless invoke local error "Runtime.ExitError"

Created on 10 Aug 2019  ·  33Comments  ·  Source: brefphp/bref

Edit: please try the workaround here: https://github.com/brefphp/bref/issues/409#issuecomment-581425967


Hello,

i followed your new documentation under https://bref.sh/docs/local-development.html and get following error if try to run
"serverless invoke local --docker -f myFunction"

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Building Docker image...
START RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATEST
END RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72
REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72  Duration: 0.00 ms   Billed Duration: 100 ms Memory Size: 1536 MB    Max Memory Used: 6 MB   
{
  "errorType": "Runtime.ExitError",
  "errorMessage": "RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"
}


/usr/lib/node_modules/serverless/lib/classes/Error.js:94
    throw new Error(inspect(e));
          ^
Error: 1
    at process.module.exports.logError.e (/usr/lib/node_modules/serverless/lib/classes/Error.js:94:11)
    at process.emit (events.js:198:13)
    at process.emit (/usr/lib/node_modules/serverless/node_modules/source-map-support/source-map-support.js:465:21)
    at /usr/lib/node_modules/serverless/node_modules/bluebird/js/release/debuggability.js:199:33
    at activeFireEvent (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/debuggability.js:242:44)
    at fireRejectionEvent (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/debuggability.js:632:14)
    at Promise._notifyUnhandledRejection (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/debuggability.js:65:9)
    at Timeout._onTimeout (/usr/lib/node_modules/serverless/node_modules/bluebird/js/release/debuggability.js:44:14)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

Any idea whats wrong?

bug

Most helpful comment

Hey everyone, I think wit the Docker images we now have a much more reliable + much faster method to run functions locally:

docker run --rm -v $(PWD):/var/task:ro,delegated bref/php-74 my-handler.php '{}'

Replace my-handler.php with the name of your handler file. The event is passed at the end as a JSON string.

As you will see, execution is near-instantaneous because we don't need the overhead of the serverless local command downloading layers.

Let me know if this works well. If it does, we can change the documentation and probably add a vendor/bin/bref command to simplify this.

All 33 comments

serverless.yml

but 7-10 don't work :-(

Thanks for the details. What is the version of serverless?

Your Environment Information ---------------------------
Operating System: linux
Node Version: 10.16.0
Serverless Version: 1.49.0
Enterprise Plugin Version: 1.3.8
Platform SDK Version: 2.1.0

Thanks. Mmh that is weird, that worked for me (it built the image with php-73:10 as you can see in the trace below)

❯ serverless invoke local --docker -f function
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Downloading layer arn:aws:lambda:us-east-2:209497400698:layer:php-73:10...
Serverless: Building Docker image...
...

Do you have those lines in serverless.yml:

plugins:
    - ./vendor/bref/bref

This might explain why the variable doesn't work.

Yes

service: app

provider:
    name: aws
    region: eu-central-1
    runtime: provided

plugins:
    - ./vendor/bref/bref

functions:
    myFunction:
        handler: index.php
        description: ''
        layers:
            - 'arn:aws:lambda:eu-central-1:209497400698:layer:php-73:6'

OK 2 things to try that comes to mind:

  • trying with version 9 of the image: if it works that could indicate that something is wrong with v10
  • cleaning up the docker image to force "serverless" to download and build it again (I think it has happened before to have a broken image, for example when hitting ctrl+c at some point)

I tried version 6 to 10 and only v6 works.
I removed all images and run the same command but still the same error

I'm trying this locally but I think either my Docker or the latest version of serverless is completely broken on my machine. I'll try this again tomorrow with a fresher mind ^^

I got the same issue (Couldn't find valid bootstrap), I had to use the full ARN to make it works.

However, my colleague @tristanbes didn't face the issue on another project.

I'm on Debian 9.11 / 4.9.0-11-amd64 and he is on macOS (latest version).

On my side, I have no problems anymore. The only thing in common here is the linux environment (I am on Mac). But that's not a big clue… I don't really know how to help further except encourage you to discuss this on the serverless project?

Slightly related: the latest versions of Serverless seem to automatically run in Docker when the runtime is provided. Maybe it might be worth updating to the latest version and try serverless invoke local -f function (without the --docker option).

Well...
On another computer I had to revert the full ARN for the short notation ${bref:layer.php-73} to make it working.

Encountered this too. Using - ${bref:layer.php-73} from the sample failed; using - 'arn:aws:lambda:us-east-1:209497400698:layer:php-73:7' worked.

Hey everyone, I think wit the Docker images we now have a much more reliable + much faster method to run functions locally:

docker run --rm -v $(PWD):/var/task:ro,delegated bref/php-74 my-handler.php '{}'

Replace my-handler.php with the name of your handler file. The event is passed at the end as a JSON string.

As you will see, execution is near-instantaneous because we don't need the overhead of the serverless local command downloading layers.

Let me know if this works well. If it does, we can change the documentation and probably add a vendor/bin/bref command to simplify this.

Invoking the command proposed:

docker run --rm -v $(pwd):/var/task:ro,delegated bref/php-74 index.php '{}'

With the following lambda at index.php:

<?php declare(strict_types=1);

require __DIR__.'/vendor/autoload.php';

lambda(function ($event) {
    return 'Hello ' . ($event['name'] ?? 'world');
});

I get the following error:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Bref\Runtime\LambdaRuntime::processNextEvent() must be callable, int given, called in /opt/bref/bootstrap.php on line 33 and defined in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php:86
Stack trace:
#0 /opt/bref/bootstrap.php(33): Bref\Runtime\LambdaRuntime->processNextEvent(1)
#1 {main}
  thrown in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php on line 86

Fatal error: Uncaught TypeError: Argument 1 passed to Bref\Runtime\LambdaRuntime::processNextEvent() must be callable, int given, called in /opt/bref/bootstrap.php on line 33 and defined in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php:86
Stack trace:
#0 /opt/bref/bootstrap.php(33): Bref\Runtime\LambdaRuntime->processNextEvent(1)
#1 {main}
  thrown in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php on line 86

The same error I nget as well with the command:

docker run --rm -v $(pwd):/var/task:ro,delegated bref/php-73 index.php '{}'

@pc-magas in #553 you were using a different layer version from the Bref version. I suggest you use the recommended serverless.yml variables from the documentation. You should also use the same PHP version as what you use in serverless.yml.

If you still have the problem, could detail your serverless.yml and complete Bref version installed?

I'm also getting this issue, is there a work around?

service: site-position-lookup-worker

provider:
    name: aws
    region: eu-west-1
    runtime: provided
    tags:
        Environment: Development
    iamRoleStatements:
        - Effect: 'Allow'
          Action:
              - 's3:Get*'
          Resource:
              - '*'

plugins:
    - ./vendor/bref/bref

functions:
    function:
        handler: index.php
        timeout: 10 # Timeout in seconds
        memorySize: 3008
        description: ''
        layers:
            - ${bref:layer.php-73}
{"errorType":"exitError","errorMessage":"RequestId: e3f14a0a-7329-10a2-b5d5-74975c92d85e Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}


 Exception -----------------------------------------------

  1

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              10.19.0
     Framework Version:         1.63.0
     Plugin Version:            3.3.0
     SDK Version:               2.3.0
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0

bref version 0.5.0 by the way

@Pi-George yes the workaround is right here, please test it and report: https://github.com/brefphp/bref/issues/409#issuecomment-581425967

@mnapoli sorry but i don't really understand much of what you said in that comment, or why I'd need to use docker run, or where to do so in conjunction with serverless commands. Here's the command I'm running.

sudo serverless invoke local --docker -f function --data '{
    <mydata>
}'

@Pi-George here is the command you can run then:

docker run --rm -v $(PWD):/var/task:ro,delegated bref/php-73 index.php '{
    <mydata>
}'

Run it instead of serverless invoke local.

Doing that (with the pwd command lowercase) gives me this

PHP Warning:  require(/var/task/vendor/autoload.php): failed to open stream: No such file or directory in /opt/bref/bootstrap.php on line 11

Warning: require(/var/task/vendor/autoload.php): failed to open stream: No such file or directory in /opt/bref/bootstrap.php on line 11
PHP Fatal error:  require(): Failed opening required '/var/task/vendor/autoload.php' (include_path='.:/opt/bref/lib/php') in /opt/bref/bootstrap.php on line 11

Fatal error: require(): Failed opening required '/var/task/vendor/autoload.php' (include_path='.:/opt/bref/lib/php') in /opt/bref/bootstrap.php on line 11

Did you run it in the project directory? Are you using Windows?

$(PWD) should return your current working directory. That will mount that in the Docker container in the /var/task directory, just like in AWS Lambda (serverless invoke local does the same thing).

Yep I ran it in the project directory, and no I'm using ubuntu. PWD in caps isn't a command, so I corrected it to lowercase $(pwd).

Maybe I did mess that up. I'm now getting


Fatal error: Uncaught ReflectionException: Class PiExt\SearchData\DAO\SearchResultsDao does not exist in /var/task/vendor/php-di/php-di/src/Definition/Source/ReflectionBasedAutowiring.php:65
Stack trace:
#0 /var/task/vendor/php-di/php-di/src/Definition/Source/ReflectionBasedAutowiring.php(65): ReflectionParameter->getClass()
#1 /var/task/vendor/php-di/php-di/src/Definition/Source/ReflectionBasedAutowiring.php(32): DI\Definition\Source\ReflectionBasedAutowiring->getParametersDefinition(Object(ReflectionMethod))
#2 /var/task/vendor/php-di/php-di/src/Definition/Source/ReflectionBasedAutowiring.php(41): DI\Definition\Source\ReflectionBasedAutowiring->autowire('Pi\\Worker')
#3 /var/task/vendor/php-di/php-di/src/Definition/Source/SourceChain.php(54): DI\Definition\Source\ReflectionBasedAutowiring->getDefinition('Pi\\Worker')
#4 /var/task/vendor/php-di/php-di/src/Container.php(154): DI\Definition\Source\SourceChain->getDefinition('Pi\\Worker')
#5 /var/task/vendor/php-di/php-di/src/Container.php(133): DI\Container->getDefinition('Pi\\Worker')
#6 /var/task/index.php(17): DI\Container->get('Pi\\Worker')
#7 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(92): {closure}(Array, Object(Bref\Context\Context))
#8 /var/task/vendor/bref/bref/src/functions.php(17): Bref\Runtime\LambdaRuntime->processNextEvent(Object(Closure))
#9 /var/task/index.php(22): lambda(Object(Closure))
#10 /opt/bref/bootstrap.php(21): require('/var/task/index...')
#11 {main}PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Bref\Runtime\LambdaRuntime::processNextEvent() must be callable, int given, called in /opt/bref/bootstrap.php on line 33 and defined in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php:86
Stack trace:
#0 /opt/bref/bootstrap.php(33): Bref\Runtime\LambdaRuntime->processNextEvent(1)
#1 {main}
  thrown in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php on line 86

Fatal error: Uncaught TypeError: Argument 1 passed to Bref\Runtime\LambdaRuntime::processNextEvent() must be callable, int given, called in /opt/bref/bootstrap.php on line 33 and defined in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php:86
Stack trace:
#0 /opt/bref/bootstrap.php(33): Bref\Runtime\LambdaRuntime->processNextEvent(1)
#1 {main}
  thrown in /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php on line 86

After trying again. Which seems to be an error on my end.

OK this looks like an error from your codebase now (AFAICT). It would guess (or hope) that things run correctly in Bref, and that there might be a problem in your autoloading configuration, or in your code (a class name doesn't match a file name?).

Maybe, I'm now stuck back on the failed opening errors and can't get the stacktrace error any more, not sure why. I'll probably come back to this once an official fix is out.

@mnapoli I am on Win 10 Pro, and was able to get the function executing locally using docker run. The key was to replace the $(PWD) with actual path as shown below.
docker run --rm -v "c:/code/serverless api":/var/task:ro,delegated bref/php-73 index.php

However, when i try to pass data to the function, it doesn't seem to be working.

docker run --rm -v "c:/code/serverless api":/var/task:ro,delegated bref/php-73 index.php '{"name":"test name"}'

Here's the index.php file

<?php declare(strict_types=1);

use Bref\Context\Context;

require __DIR__ . '/vendor/autoload.php';

return function ($event, Context $context) {
    return sprintf('Event: %s | Context: %s | %s', json_encode($event), json_encode($context), 'Hello ' . ($event['name'] ?? 'world'));
};

Irrespective of what i pass in the JSON, output is always

Event: null | Context: {} | Hello world

  1. how do i pass event data?
  2. how do i pass context info?

If this https://github.com/brefphp/bref/issues/409#issuecomment-581425967 gets the new way of running functions locally, what happens when we depends on a nodejs + bref php layout ?

Also, it's really stupid, but i'm struggling passing a test.json file containing the data.
Tried:

docker run --rm -v $(PWD):/var/task:ro,delegated bref/php-74 bin/consume < test.json

-> lambda recieves[] for $event

docker run --rm -v $(PWD):/var/task:ro,delegated bref/php-74 bin/consume $(cat test.json)

-> lambda recieves null for $event because the files contains breaking lines (for better maintainability)

Also, I came on this issue because of the "Runtime.ExitError", and I had to try 3 different version of the php7.4 layer before gettin the function to run.

  - arn:aws:lambda:eu-west-2:209497400698:layer:php-74:7 // Working 🎉
  - arn:aws:lambda:eu-west-2:209497400698:layer:php-74:8 // Runtime.ExitError
  - arn:aws:lambda:eu-west-2:209497400698:layer:php-74:9 // Runtime.ExitError
  - ${bref:layer.php-74} // // Runtime.ExitError

I really hope new bref user never stamble upon this issue because it's crazy :(

Yeah it is really annoying. I stumble on this in trainings too, and it seems to be random.

I think there is a problem in the part of Serverless that builds the Docker images. I'm not sure I can do anything about it myself.

Now unfortunately I haven't had time to document the other method too (the one where we invoke with Docker directly), and I don't remember by memory how to do all this. If anyone wants to contribute that that would be awesome.

for me : #647 did fix

PHP Warning: require(/var/task/vendor/autoload.php): failed to open stream: No such file or directory in /opt/bootstrap on line 17

Great news, I've been working on a solution that solves all the problems (AFAICT), I'm really excited about it: #785

Feedback is welcome!

Will be solved in v1.0 by #785 (vendor/bin/bref local hello).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kwn picture kwn  ·  8Comments

t-geindre picture t-geindre  ·  5Comments

tlfbrito picture tlfbrito  ·  4Comments

mnapoli picture mnapoli  ·  5Comments

nealio82 picture nealio82  ·  6Comments