holy-lambda

octahedrion 2024-02-20T11:41:01.790869Z

when I do bb hl:compile I get

[holy-lambda] PATH .holy-lambda/build/output.jar does not exists.. Exiting!

octahedrion 2024-02-21T15:43:15.486079Z

hello again, yesterday I was so tired I was wrong that it had worked. I'd put a hack in my code to alter-var-root the autogenerated -main to invoke it with my handler name regardless of the args to -main so that I could proceed, but forgot to remove it when I tested it after following your advice to change settings in template.json. When I retried today it still doesn't receive the correct handler name to lookup a handler in -main and nothing I change in template.json seems to make any difference. Would you mind checking it please ? https://pastebin.com/kt787ms1

Karol Wójcik 2024-02-21T16:13:10.645739Z

What runtime do you use? Is it native or Clojure one backed with Docker.

Karol Wójcik 2024-02-21T16:13:19.327059Z

It seems it’s docker based, right?

Karol Wójcik 2024-02-21T16:15:33.913819Z

Hope you are also using the -t parameter with SAM to specify the alternative template.json.

octahedrion 2024-02-22T05:40:32.124349Z

Clojure one backed with Docker

octahedrion 2024-02-22T05:44:10.386249Z

sam build uses template.json if it exists and converts it to .aws-sam/build/template.yaml

Karol Wójcik 2024-02-22T05:57:36.608449Z

Have you read this?

octahedrion 2024-02-22T06:10:31.334299Z

yes that's the example I'm following

octahedrion 2024-02-22T06:13:16.597969Z

I think I could solve my problem if I knew where the args for -main come from

octahedrion 2024-02-22T08:26:34.394479Z

ok the answer is it comes from Dockerfile , the line:

CMD java -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -jar output.jar "org.me.mynamespace.MyHandlerFn"

octahedrion 2024-02-22T08:28:05.863149Z

the fully qualified function name at the end of that line is what is received by HL generated -main which is then used via lookup in the map PRVL_ROUTES to invoke your function when you test it with sam local invoke

Karol Wójcik 2024-02-22T08:34:25.157159Z

Yes.

octahedrion 2024-02-22T08:34:41.663849Z

two of my life goals were to never need to use NPM or Docker, and I have failed at both

octahedrion 2024-02-22T08:35:08.030559Z

(I don't know anything about Docker)

Karol Wójcik 2024-02-20T13:35:33.674979Z

Are you sure you running bb hl:compile and not bb hl:executable?

octahedrion 2024-02-20T13:36:26.771679Z

yes

Karol Wójcik 2024-02-20T13:37:08.502599Z

Do you mind sharing a reproduction?

octahedrion 2024-02-20T13:38:28.903959Z

it's the same as the example given in the Getting Started guide but with my.namespace instead of basic.example

octahedrion 2024-02-20T13:40:40.639349Z

I'm copying the built jar over to .holy-lambda/build/output.jar in my build.clj instead until I find out why

👍 1
octahedrion 2024-02-20T13:41:45.841279Z

I'm also getting this error when I test it with sam local invoke MyHandler

[holy-lambda] Runtime error:
{:via [{:type java.lang.Exception, :message "[holy-lambda]: Handler my.lambda not found!", :at [fierycod.holy_lambda.custom_runtime$next_iter invokeStatic "custom_runtime.clj" 76]}],

octahedrion 2024-02-20T13:55:41.725499Z

I know it loads my namespace because I put a println in. It looks like it's to do with the routing via the generated -main

octahedrion 2024-02-20T15:04:47.324189Z

when doing sam local invoke MyHandler , what should I expect to be passed into -main ? because currently it gets the namespace of the -main function, not the Entrypoint of the template

octahedrion 2024-02-20T15:14:29.296769Z

a look at PRVL_ROUTES shows that it should be receiving the fully qualified handler name e.g. .namespace.HandlerName as that's the key in the map, but it only receives the namespace

Karol Wójcik 2024-02-20T15:15:17.159519Z

Could you kindly show me your code?

octahedrion 2024-02-20T15:15:22.859449Z

sorry I can't

Karol Wójcik 2024-02-20T15:15:38.669359Z

What is the entrypoint in your namespace?

octahedrion 2024-02-20T15:15:51.654619Z

I've tried everything for the entrypoint!

octahedrion 2024-02-20T15:16:01.050299Z

it doesn't seem to be used

Karol Wójcik 2024-02-20T15:16:14.424289Z

Sam local invoke sends nothing by default.

octahedrion 2024-02-20T15:16:30.997279Z

ohhhh

octahedrion 2024-02-20T15:17:04.650969Z

well how do I simulate a request to my handler then ?

Karol Wójcik 2024-02-20T15:17:18.365629Z

Is it an API?

octahedrion 2024-02-20T15:17:22.571529Z

yes

Karol Wójcik 2024-02-20T15:17:43.471999Z

sam local start-api

octahedrion 2024-02-20T15:18:26.090659Z

ok I'll try that meanwhile can I confirm that I can use a template.json instead of template.yaml for sam build ? because I don't want to use yaml

octahedrion 2024-02-20T15:19:35.054089Z

I can see that when I do sam build it generates .aws-sam/build/template.yaml which is the same as my template.json

octahedrion 2024-02-20T15:21:50.546739Z

(with sam local start-api I get the same :message "[holy-lambda]: Handler my.namespace not found!" error

Karol Wójcik 2024-02-20T15:25:52.445319Z

What are you trying to achieve by sending the namespace to the entrypoint?

Karol Wójcik 2024-02-20T15:26:02.991399Z

It should be qualified var.

Karol Wójcik 2024-02-20T15:26:22.022929Z

Like: #’my.namespace/some-function

Karol Wójcik 2024-02-20T15:27:29.058629Z

Not sure about sam build part, but you can use any deployment tool you want.

octahedrion 2024-02-20T15:40:20.998699Z

"What are you trying to achieve by sending the namespace to the entrypoint?" I'm not! that's what my the generated -main of the namespace of my handler is receiving

octahedrion 2024-02-20T15:49:16.674289Z

what I'd like to know is where do the args to -main come from when I do sam local invoke Handler ?

Karol Wójcik 2024-02-20T16:07:17.785139Z

Okay, then your template.yml is wrong.

Karol Wójcik 2024-02-20T16:08:33.348249Z

Can you at least show me the definition of your handler in template.yml?

Karol Wójcik 2024-02-20T16:12:16.101049Z

Main arguments most likely are not used in your case. All lambda environments can obtain the handler name from „_HANDLER” environment variable.

octahedrion 2024-02-20T16:12:55.572229Z

Handler: my.namespace.lambda/MyHandler

Karol Wójcik 2024-02-20T16:13:06.211949Z

Thus when you are doing sam local Invoke SomeFunction there needs to be mapping between the function and the function in some Clojure namespace.

octahedrion 2024-02-20T16:14:36.811049Z

yes I know that the PRVL_ROUTES is correct because it's a map between the fully qualified name of my handler and its corresponding fully qualified var

Karol Wójcik 2024-02-20T16:15:25.611459Z

Okay, handler name is wrong.

octahedrion 2024-02-20T16:15:28.484429Z

but the args received by -main is just the namespace of that -main and the handler function

Karol Wójcik 2024-02-20T16:16:39.276659Z

It has to be: my.namespace.lambda.MyHandler

octahedrion 2024-02-20T16:17:05.375709Z

hehehe I'm sure I've tried that but let me try it again...

octahedrion 2024-02-20T16:20:23.660509Z

it works

Karol Wójcik 2024-02-20T16:20:38.776639Z

😉

Karol Wójcik 2024-02-20T16:20:42.325339Z

Cool!

octahedrion 2024-02-20T16:20:52.738299Z

I'm tired I probably messed something else up then

Karol Wójcik 2024-02-20T16:21:10.630999Z

No worries mate! Happens to everyone ;)

octahedrion 2024-02-20T16:21:40.913919Z

I think what would help is a few comments in the example files to clarify what each entry should be

octahedrion 2024-02-20T16:23:31.711999Z

I'm also wondering whether the template.json could be at least partially auto-generated

octahedrion 2024-02-20T16:24:24.773359Z

anyway I'm new to this so thanks for all your help!