seek-oss / serverless-haskell

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

fatal error exe is not defined #113

Closed Jimbo4350 closed 4 years ago

Jimbo4350 commented 4 years ago

I have written a simple servant server and converted it into a lambda function that queries a MySQL db in amazon RDS. I can get it to work locally with serverless offline start however when I deploy it (serverless deploy) I get the following error in my dashboard when trying to access my simple test endpoint.

10:24:00 am
START RequestId: 9577f510-712c-4204-b9ac-05d75defcb42 Version: $LATEST
10:24:00 am
2019-10-28T14:24:00.167Z    9577f510-712c-4204-b9ac-05d75defcb42    INFO    
10:24:00 am
2019-10-28T14:24:00.169Z    9577f510-712c-4204-b9ac-05d75defcb42    ERROR   ReferenceError: exe is not defined
    at Object.<anonymous> (/var/task/s_apigw.js:14:66)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at _tryRequire (/var/runtime/UserFunction.js:75:12)
    at _loadUserApp (/var/runtime/UserFunction.js:95:12)
10:24:00 am
2019-10-28T14:24:00.185Z    9577f510-712c-4204-b9ac-05d75defcb42    ERROR   Invoke Error    {
    "errorType": "ReferenceError",
    "errorMessage": "exe is not defined",
    "stack": [
        "ReferenceError: exe is not defined",
        "    at Object.<anonymous> (/var/task/s_apigw.js:14:66)",
        "    at Module._compile (internal/modules/cjs/loader.js:778:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)",
        "    at Module.load (internal/modules/cjs/loader.js:653:32)",
        "    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:585:3)",
        "    at Module.require (internal/modules/cjs/loader.js:692:17)",
        "    at require (internal/modules/cjs/helpers.js:25:18)",
        "    at _tryRequire (/var/runtime/UserFunction.js:75:12)",
        "    at _loadUserApp (/var/runtime/UserFunction.js:95:12)"
    ]
}
10:24:00 am
END RequestId: 9577f510-712c-4204-b9ac-05d75defcb42
10:24:00 am
REPORT RequestId: 9577f510-712c-4204-b9ac-05d75defcb42  Duration: 30.73 ms  Billed Duration: 100 ms Memory Size: 1024 MB    Max Memory Used: 83 MB  Init Duration: 210.80 ms    
koterpillar commented 4 years ago

Can you please share your serverless.yml?

Jimbo4350 commented 4 years ago

@koterpillar

org: jimbo4350
app: minimal-example-rds
service: serverless-minimal-example-rds

provider:
  name: aws
  runtime: haskell
  region: ap-southeast-2
  timeout: 100

functions:
  apigw:
    handler: serverless-haskell-example.api-exe
    events:
      - http:
          path: item/test
          method: get

plugins:
  - serverless-haskell
  - serverless-offline

If I rename serverless-haskell-example.api-exe to serverless-haskell-example.apigw (and make the corresponding change in the .cabal file, the lambda function then times out on AWS but still works locally (serverless offline start)

koterpillar commented 4 years ago

I don't see anything wrong with this file; perhaps you can upload a minimal project demonstrating this behaviour somewhere?

Alexey

Jimbo4350 commented 4 years ago

@koterpillar https://github.com/Jimbo4350/simple-serverless-servant

koterpillar commented 4 years ago
Error: ENOENT: no such file or directory, copyfile '/.../simple-serverless-servant/.stack-work/install/.../8.4.3/bin/api-exe' -> '/.../simple-serverless-servant/api-exe'

The reason for this is in serverless.yml, the handler must match the built executable, the function name can be arbitrary (it will be used in AWS). In your example:

functions:
  apigw:  # this is just for AWS
    handler: serverless-haskell-example.api-exe  # this must match `package.yaml`

After changing handler to handler: serverless-haskell-example.apigw, I was able to package the application without errors, see https://github.com/koterpillar/simple-serverless-servant.

If you're still having problems, please attach the output of running:

stack --version
npm --version
npm ci
`npm bin`/sls package
Jimbo4350 commented 4 years ago

@koterpillar Thank you. However I am still having issues. I have tested the connectivity to my aws db in ghci as follows:

*Main Database Lib ServantShim> allItems 
[Item {_itemId = 1},Item {_itemId = 2}]

However deploying my lambda function and testing the endpoints I get: {"message": "Endpoint request timed out"}

koterpillar commented 4 years ago

Does it mean the executable is deployed to AWS and starts correctly there?

What is producing the "Endpoint request timed out" message?

Jimbo4350 commented 4 years ago

So I have tested my lambda function locally with serverless-offline with the following commands:

sls offline start                                                                                             
Serverless: Building handler apigw with Stack...
Serverless: Starting Offline: dev/ap-southeast-2.

Serverless: Routes for apigw:
Serverless: GET /item/test
Serverless: POST /{apiVersion}/functions/serverless-minimal-example-final-dev-apigw/invocations

Serverless: Offline [HTTP] listening on http://localhost:3000
Serverless: Enter "rp" to replay the last request

Serverless: GET /item/test (λ: apigw)

I navigate to localhost:3000 as see the following:

{"statusCode":404,"error":"Serverless-offline: route not found.","currentRoute":"get - /","existingRoutes":["get - /item/test","post - /{apiVersion}/functions/serverless-minimal-example-final-dev-apigw/invocations"]}

I then navigate to: http://localhost:3000/item/test which responds with my test data in my aws db: [{"_itemId":1},{"_itemId":2}]

Does it mean the executable is deployed to AWS and starts correctly there?

I deployed the executable to aws then I navigate to the API Gateway endpoint

What is producing the "Endpoint request timed out" message?

My browser when I navigate to the endpoint

koterpillar commented 4 years ago

Look into the CloudWatch logs (or use sls logs) to see what's happening on AWS.

Jimbo4350 commented 4 years ago

Just lists timeouts: 2019-11-02T00:17:01.797Z 7f3ea16b-5d9f-4565-ba94-17037bc51f9a Task timed out after 100.06 seconds

koterpillar commented 4 years ago

Do you mind adding a logging statement to the start of your main function to see if it's executed then?

Jimbo4350 commented 4 years ago

@koterpillar I added a logging statement and it appeared in my logs. I think I have found the issue, it may be due to my usage of beam-core. I'll follow up in a bit.

Jimbo4350 commented 4 years ago

@koterpillar False lead :man_shrugging:

koterpillar commented 4 years ago

So it seems like the function is deployed correctly, and you have logs to debug it further.

Jimbo4350 commented 4 years ago

@koterpillar found this in the logs: ./apigw: /lib64/libm.so.6: version GLIBC_2.27 not found (required by ./apigw)

koterpillar commented 4 years ago

That's interesting, would you mind opening a new issue with that, for better tracking?