This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-13
Channels
- # admin-announcements (1)
- # announcements (40)
- # aws (2)
- # babashka (46)
- # babashka-sci-dev (106)
- # beginners (31)
- # cider (5)
- # circleci (2)
- # clj-kondo (48)
- # clojure (118)
- # clojure-belgium (1)
- # clojure-chicago (3)
- # clojure-europe (19)
- # clojure-ireland (3)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-spec (10)
- # clojure-uk (4)
- # clojurescript (18)
- # community-development (5)
- # core-async (159)
- # cursive (16)
- # datomic (16)
- # etaoin (1)
- # fulcro (21)
- # funcool (14)
- # graalvm (5)
- # gratitude (4)
- # holy-lambda (28)
- # jobs (1)
- # jobs-discuss (1)
- # kaocha (1)
- # lsp (12)
- # malli (21)
- # meander (12)
- # music (1)
- # off-topic (8)
- # portal (5)
- # react (18)
- # reitit (1)
- # releases (4)
- # remote-jobs (1)
- # shadow-cljs (56)
- # timbre (4)
Hi guys, I'm trying to create a native executable which is using the cognitect-aws library. Unfortunately the required service.edn
file seems to be omitted during the execution of bb hl:native:executable
. I've already generated the native configuration files via bb hl:native:config
task and added the "\\Qcognitect/aws/dynamodb/service.edn\\E"
pattern to the includes array. But still, the EDN file is missing in the final bundle. Am I missing something?
Yes you're missing something
https://fierycod.github.io/holy-lambda/#/native-backend?id=agent-in-context-calls Add agent in context call to a service you are using, so that native:config can gather the required EDN files for you.
For instance:
(agent/in-context
(aws/invoke @dynamodb-client {}))
Thank you @UJ1339K2B for this hint. Wrapping single function calls with the in-context
macro in combination with the additional includes
pattern seems to fix the described issue. It's not quite clear to me how to use the in-context
macro exactly and what is the purpose of agents in this context.
Have you read the documentation about GraalVM tracing agent? Basically GraalVM requires a lot of statically provided information to correctly produce a working binary. Reflection and resources are sometimes not covered in the main path of analysis therefore it's required to either populate configuration by hand or to generate the configuration via the Java GraalVM tracing agent. The agent analyses the additional code paths provided in agent/in-context call and produces the required configuration for valid binary. If you cover all the reflective paths/(or paths of code where the resources are used), then you don't need to add any additional entries by hand.
You can try removing the native-configuration entirely. Then regenerate the folder via bb native:conf supposing agent/in-context calls are still in the code. You will see that you don't have to add anything to configuration by hand in this case.
@U5ABB4GQP let me know if it makes sense to you
Hi @UJ1339K2B, thank you for your support. I've studied the documentation you mentioned above. The point is that I've managed to build a simple function which should read an entry from a DynamoDB table. I've compiled the function using holy-lambda babashka tasks (compile, config, native-executable) without any errors and deployed it to AWS. But unfortunately the function returns nil
instead of the expected result map. I'm pretty sure it has nothing to do with holy-lambda functionality.
How to you return the value?
The code looks like this (simplified):
(:require
[cognitect.aws.client.api :as aws]
[cognitect.aws.credentials :as credentials]
[fierycod.holy-lambda.agent :as agent]
[fierycod.holy-lambda.core :as h]
[fierycod.holy-lambda.response :as hr])
(let [client (make-client ,,,)
result (agent/in-context
(aws/invoke client {:op :Query :request q}))]
(hr/json result))
Where is an entrypoint and lambda definition?
sorry, the known issue with code examples on the internet:slightly_smiling_face:
(:require
[cognitect.aws.client.api :as aws]
[cognitect.aws.credentials :as credentials]
[fierycod.holy-lambda.agent :as agent]
[fierycod.holy-lambda.core :as h]
[fierycod.holy-lambda.response :as hr])
(defn fetch [client q]
(agent/in-context
(aws/invoke client q)))
(defn LambdaFunction [{:keys [event ctx] :as _request}]
(let [http-client (agent/in-context (aws/default-http-client))
client (agent/in-context
(aws/client {:api :dynamodb
:region "eu-central-1"
:credentials-provider (credentials/default-credentials-provider http-client)}))
q {:op :Query
:request {:TableName "MyTable"
:KeyConditions {"PartitionKey" {:AttributeValueList [{:S "SomeValue"}]
:ComparisonOperator "EQ"}
"CacheKey" {:AttributeValueList [{:S "OtherValue"}]
:ComparisonOperator "EQ"}}}}
result (fetch client q)]
(hr/json result)))
(h/entrypoint [#'LambdaFunction])
This is not how agent/in-contex
t work. You have to include aws/in-context
call in the top level of your code (not in function).
Can you confirm if your query returns a proper result in your REPL?
Yes, I'm able to retrieve the expected result using the defined LambdaFunction locally. But to achieve this I have to remove the agent/in-context calls. I'll try your suggestion out, tnx.
Can you print the result and check what is there on Cloudwatch? Btw does your Lambda have permissions to read from DynamoDB? I do also recommend building the native executable and trying it out locally via sam local invoke.
I cannot confirm that the lambda gets actually executed. I've doublechecked the lambda permissions and it looks correct. Another thing which confuses me is the fact that all prints within the in-context
macro gets swallowed and I do not see any output.
Can you execute the Lambda locally?
Yeah. Uncaught error. See the definition of in-context: https://github.com/FieryCod/holy-lambda/blob/master/src/fierycod/holy_lambda/agent.clj#L20
> Can you execute the Lambda locally? Unfortunately I can't do it at the moment without further investigation. AWS SAM assumes that you use API Gateway but we don't. To keep up with my deadline I'll pause this PoC to proceed on the existing lambda implementation written in Rust. Nevertheless, here's my (interim) conclusion: This project looks very promising and could help to lower the entry barrier into the Clojure+Lambda topic. Thanks for your work! But it's very hard to proceed smoothly without deep understanding of underlying technologies (well, like almost always). The cognitect-aws library is exceptionally dynamic compared to other libs. Cheers, Andreas
Thanks for your insights. As far as I remember a function can be called locally even without the AWS Api Gateway. Anyway all the best! If you ever need any help don't hesitate to ask. ;)
Do I have to mount my local host files from resources/native-configuration
into the docker container via [:holy-lambda/options :docker :volumes]
in my bb.edn
file?
All files from the directory in which the native:conf runs is auto mounted in docker context.