Jets call does not find route

Greetings,

I’m struggling to observe the advertised behavior of jets call. I have a simple brand new jets application created with: jets new my-service --mode api --database=postgres

I have scaffolded a single samples controller with a single Sample model with a single column kit_id. I have also changed the catchall route to route to samples#index.
I have verified database connectivity using jets server and hitting the endpoints using curl.

However when I use jets call as follows I get unexpected behavior.
jets call samples_controller-show '{"id": 1}' --local

Local mode enabled!
Function name: s2-dev-samples_controller-show
I, [2020-08-13T07:20:34.039692 #32378]  INFO -- : Started  "" for  at 2020-08-13 07:20:34 +0000
I, [2020-08-13T07:20:34.040031 #32378]  INFO -- : Processing SamplesController#index
I, [2020-08-13T07:20:34.040405 #32378]  INFO -- :   Event: {"queryStringParameters":{"id":1},"body":null,"pathParameters":null}
I, [2020-08-13T07:20:34.040753 #32378]  INFO -- :   Parameters: {"id":1}
I, [2020-08-13T07:20:34.174340 #32378]  INFO -- : Completed Status Code 200 in 0.134671207s

I would expect jets to invoke SamplesController#show , not SamplesController#index.
I have spent the better part of the day investigating this and narrowed it down to the middleware stack. It appears that an environment variable lambda.meth is correctly set to ‘:show’, but the router does not seem to respect that.

Since nobody else seems to be experiencing this issue I assume it is user error, but I am at my wits end as to what I’m doing incorrectly.

Any help is greatly appreciated.
-Josh

Ok. As expected it was user error. For posterity (and those of you new to both lambda functions and jets)
the documentation is a bit light on the arguments that are required to invoke a lambda function.

Specifically you need to specify:

"path": "/posts",  // the path as defined in routes.rb,  in this case to PostsController
"pathParameters": {"id": "5"},  // This is the part of the route that matches :id 
"body", "{\"post\": {\"title\": \"Title of the new post\"}}", // What you would pass in via the body for POST, PUT, PATCH
"httpMethod", "POST" // the http method you want the router to resolve.

I still have not successfully invoked jets call without --no-lambda-proxy, but that is a small thing, at least I am up and running.

I was also thrown for a loop because the lambda function would timeout instead of failing when the event did not contain the appropriate parameters.

Regardless things are working now.

1 Like