seek-oss / serverless-haskell

Deploying Haskell applications to AWS Lambda with Serverless
MIT License
215 stars 22 forks source link

Offline even with `--useDocker` tries to use lambci/lambda:haskell which doesn't exist #138

Closed danwdart closed 4 years ago

danwdart commented 4 years ago
offline: Warning: found unsupported runtime 'haskell' for function 'emailme'
No valid trust data for haskell
offline: Failure: Command failed with exit code 1: docker pull --disable-content-trust=false lambci/lambda:haskell
No valid trust data for haskell
Error: Command failed with exit code 1: docker pull --disable-content-trust=false lambci/lambda:haskell
No valid trust data for haskell
    at makeError (/home/dwd/code/mine/projects/haskell/slsdemo/node_modules/serverless-offline/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/home/dwd/code/mine/projects/haskell/slsdemo/node_modules/serverless-offline/node_modules/execa/index.js:114:26)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at Function._pullImage (/home/dwd/code/mine/projects/haskell/slsdemo/node_modules/serverless-offline/dist/lambda/handler-runner/docker-runner/DockerImage.js:35:7)

Tried to use provided as runtime but I just get:

offline: [502] {"errorType":"exitError","errorMessage":"RequestId: 2cf06505-d533-17c1-57a0-edde6a345edc Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}

Any ideas?

koterpillar commented 4 years ago

Can you please share your serverless.yml? This is being tested in the integration tests (https://github.com/seek-oss/serverless-haskell/blob/master/integration-test/skeleton/serverless.yml, https://github.com/seek-oss/serverless-haskell/blob/master/integration-test/run.sh#L162-L172).

seanhess commented 4 years ago

@danwdart I'm getting this same error while trying to get serverless-offline to work. I'm testing the route in the browser by visiting http://localhost:3000/dev/value. The function works when I use sls invoke local -f get-value

Error

$ sls offline --useDocker
offline: Starting Offline: dev/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:3002

   ┌─────────────────────────────────────────────────────────────────────────────┐
   │                                                                             │
   │   GET | http://localhost:3000/dev/value                                     │
   │   POST | http://localhost:3000/2015-03-31/functions/get-value/invocations   │
   │                                                                             │
   └─────────────────────────────────────────────────────────────────────────────┘

offline: [HTTP] server ready: http://localhost:3000 🚀
offline:
offline: Enter "rp" to replay the last request

offline: GET /dev/value (λ: get-value)

offline: Warning: found unsupported runtime 'haskell' for function 'get-value'
No valid trust data for haskell
offline: Failure: Command failed with exit code 1: docker pull --disable-content-trust=false lambci/lambda:haskell
No valid trust data for haskell
Error: Command failed with exit code 1: docker pull --disable-content-trust=false lambci/lambda:haskell
No valid trust data for haskell

Serverless.yaml

service: demo

provider:
  name: aws
  runtime: haskell

functions:
  get-value:
    handler: server.get-value
    events:
      - http:
          path: value
          method: get

    # Here, mypackage is the Haskell package name and myfunc is the executable
    # name as defined in the Cabal file. The handler field may be prefixed
    # with a path of the form `dir1/.../dirn`, relative to `serverless.yml`,
    # which points to the location where the Haskell package `mypackage` is
    # defined. This prefix is not needed when the Stack project is defined at
    # the same level as `serverless.yml`.

plugins:
  - serverless-haskell
  - serverless-offline
seanhess commented 4 years ago

This repository reproduces the issue:

https://github.com/seanhess/serverless-haskell-miso/tree/master/server

seanhess commented 4 years ago

@koterpillar If you have a minute can you chime in on what I might be doing wrong?

koterpillar commented 4 years ago

I am able to use both local invocation and sls-offline in the above repository. Here's what I've done after cloning:

$ npm install
$ `npm bin`/sls package
# this took a long time
$ echo '{}' | `npm bin`/sls invoke local -f hello
Serverless: Building handler hello with Stack...
Serverless: Packaging service...
Serverless: Downloading base Docker image...
Serverless: Writing Dockerfile...
Serverless: Building Docker image...
START RequestId: 94c8f046-b51f-1ed1-d0ae-0b41c58f120f Version: $LATEST
END RequestId: 94c8f046-b51f-1ed1-d0ae-0b41c58f120f
REPORT RequestId: 94c8f046-b51f-1ed1-d0ae-0b41c58f120f  Init Duration: 261.22 ms        Duration: 26.38 ms      Billed Duration: 100 ms Memory Size: 1024 MB    Max Memory Used: 16 MB

{"errorType":"ErrorCall","errorMessage":"Error in $: key \"resource\" not found\nCallStack (from HasCallStack):\n  error, called at src/AWSLambda/Handler.hs:93:19 in serverless-haskell-0.11.3-3CH7TWIJP4G1p2vduMHGCm:AWSLambda.Handler"}

  Error --------------------------------------------------

  Error: Failed to run docker for provided image (exit code 1})
      at [omitted]/serverless-haskell-miso/server/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:488:21

     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:          darwin
     Node Version:              14.5.0
     Framework Version:         1.74.1
     Plugin Version:            3.6.15
     SDK Version:               2.3.1
     Components Version:        2.31.10
$ `npm bin`/sls offline start --useDocker
Serverless: Building handler value with Stack...
Serverless: Building handler hello with Stack...
offline: Starting Offline: dev/us-east-1.
offline: Offline [http for lambda] listening on http://localhost:3002

   ┌─────────────────────────────────────────────────────────────────────────┐
   │                                                                         │
   │   GET | http://localhost:3000/dev/hello/{name}                          │
   │   POST | http://localhost:3000/2015-03-31/functions/hello/invocations   │
   │                                                                         │
   └─────────────────────────────────────────────────────────────────────────┘

offline: [HTTP] server ready: http://localhost:3000 🚀
offline:
offline: Enter "rp" to replay the last request

offline: GET /dev/hello/blah (λ: hello)
Lambda API listening on port 9001...

START RequestId: 531b140b-b7f0-1dc6-2e8e-47f54b04ba12 Version: $LATEST

This should go to logs

END RequestId: 531b140b-b7f0-1dc6-2e8e-47f54b04ba12
REPORT RequestId: 531b140b-b7f0-1dc6-2e8e-47f54b04ba12  Init Duration: 200.49 ms        Duration: 36.36 ms      Billed Duration: 100 ms Memory Size: 1024 MB    Max Memory Used: 16 MB

offline: GET /dev/hello/blah (λ: hello)
START RequestId: 2323f925-996a-12db-5cfb-288b8f032417 Version: $LATEST

This should go to logs

END RequestId: 2323f925-996a-12db-5cfb-288b8f032417
REPORT RequestId: 2323f925-996a-12db-5cfb-288b8f032417  Duration: 4.61 ms       Billed Duration: 100 ms Memory Size: 1024 MB    Max Memory Used: 19 MB

^Coffline: Got SIGINT signal. Offline Halting...
offline: Halting offline server

While the offline server was running, in another terminal:

$ curl http://localhost:3000/dev/hello/blah
Hello, blah
seanhess commented 4 years ago

Well, it's working for me now too. I have no idea what changed. Thank you for your help.

I didn't open this issue, but I was getting the exact same error as the OP earlier. You may want to consider closing.

koterpillar commented 4 years ago

If you find a way to reproduce it (from a clean checkout), please open a new issue.

danwdart commented 3 years ago

I do get this now but only when I specifically use runtime: provided on purpose.

koterpillar commented 3 years ago

The plugin manages the runtime and will not consider any runtime: provided functions as Haskell.

danwdart commented 3 years ago

Yep - just for those who came across this, that's what they need to know.