For those who use AWS, which of these is the preferable lib to use? https://github.com/cognitect-labs/aws-api https://github.com/mcohen01/amazonica
they are very different approaches
amazonica is a clojure wrapper for the Java SDK
aws-api is a data-oriented and data-driven Clojure API directly to the AWS http api
Would it be possible to adapt aws-api for cljs?
that has been discussed
I don't know the status of it
My use case would be using CLJS for AWS lambda
^^ the issue to follow
Nice, thanks
Would it just take converting clj files to cljc?
“just”
no
you would need a cljs http library instead (maybe other things too, I don't know)
Makes sense
conceptually there is no reason that can't work afaik
we are making moves towards being able to being able to support cljs but cljs isn’t in the short term milestones
Is there an existing cljs solution for the AWS api?
I don't think amazonica does that for cljs
Maybe interop with aws-sdk-js?
seems like that would be the obvious thing to do
Apart from http there are also signing routines that need porting to cljs
Is that done on a clj reader level or a namespace level?
Signing routines are not terribly complicated, but we’re trying to move forward everything compatibly
And that can be tricky
@mruzekw what makes you interested in cljs over clj?
I plan on using AWS Lambda
Though I’m not opposed to using CLJ with GraalVM
GraalVM is not possible with these dependencies AFAIK
Native-image, that is
What is your SLA for startup time?
I mean, I’d like to get cold start to <= 500ms and warm <=200ms
What sorts of dependencies are you interested in running within lambda? Sorry for the 20 questions, doing research :)
haha no worries
I’m in the preliminary infra planning stages so this may change and may be incomplete, but I’m mainly looking at using the RDSDataServer API to access an Aurora Serverless SQL cluster
This is just for now. I could see a use for a queue component
One thing to consider is if you need to run lambdas in VPC, which would increase the cold start time
Hmm good to know, VPC restricts public access?
It allows lambda to talk to services that are inside a VPC that are not accessible from outside
Okay, will have to think that through
Do you know how much ms on average accessing through a VPC is?
AWS launched optimizations for cold starts for lambdas in VPC few weeks ago, so I don’t know the current situation. It used to be in order of few seconds for cold starts and no difference in warm starts, if I remember correctly.
https://aws.amazon.com/blogs/compute/announcing-improved-vpc-networking-for-aws-lambda-functions/
Wow a few seconds is significant
933 ms is better but not great
But I guess that’s just on cold
Is there a good doc ref for the AWS HTTP level API?
All I can find are the SDK docs
That is what aws-api solves for you.
basically there is a json based datastructure for all the api's but I'm not aware of a complete doc reference.
Hmm alright
> Each AWS SDK has its own copy of the data descriptions in their github repos. We use aws-sdk-js as the source for these, and release individual artifacts for each api.
Gotcha
I prefer the aws-api because then i'm not stuck using builders like the java sdk
query.firstParam().secondParam().build()
type API?
One word, RequestBuilder
.
Does aws-api take outside PRs?
No, but they take issues
Kk
I may just use aws/aws-sdk-js
in the mean time
Editorial: I’m all for faster startup times, but cold start is talked about way too much without surrounding use-cases
(That’s why I’m probing for details)
Well I’m hoping to have lambdas that serve API responses
Servicing a frontend SPA
I’d like the user operations to be quick
Thus below 1s
if people are using it, then things aren't cold right?
Right, within a timeout
If people don’t use it for say 10 mins it destructs
Set a cloudwatch event to ping your stuff every n minutes. Then it's never cold.
Sure, not a bad idea
It doesn’t cost to keep a fn warm?
nope
Nice
That keeps one lambda instance warm, you’ll get cold starts if you happen to need more than one simultaneously.
you can invoke a lambda to invoke your lambdas
Dynamically?
Like it knows which are warm already?
This coldstart thing is almost never an issue unless you have a thundering herd scenario.
If you make a heartbeat lambda which heartbeats all your other possible lambdas then this is solved, right?
Where does the heartbeat originate?
cloudwatch event rule
I think there’s a timelimit on a running lamnda
Ohhh
Last heading: > What Is The Effect Of VPC Access?
Looks like VPC only slows a cold start by about 0.1s
That is a new feature. It used to be a lot worse.
I am grateful
That’s on my list to watch
Do you have a tldr/w?
start times depend on lot of things, like jar size. cold starts are faster in clojurescript, and warm starts are faster in clojure. Clojure(script) has some extra start time cost on top of nodejs/jvm.
Sure, matches with my research so far
Thanks for all your input all 🙏 🙂
also low memory lambdas have more varying performance than higher memory (more expensive) lambdas. That is you get some minimum amount of cpu but might get more if you are lucky.
if cold starts are your problem, then isn't the real problem no one is using your stuff?
given settings also affect how fast the code slugs are pulled down
and larger code slugs => slower to pull
that's partly what Lambda Layers help with
coldstart is but one aspect
of a much larger picture
I’ve made this leiningen template to help creating lambda projects for clojure: https://github.com/jsyrjala/aws-lambda-serverless/
@jsyrjala Do you know of any other Clojure on Lambda resources?
Can’t remember anything else that I have used.
Mostly lambdas I have done are backend stuff where cold starts do not matter at all.
@mruzekw I was pointed to this repo recently when looking for clj on AWS Lambda resources: https://github.com/StediInc/lambda. Looks useful, haven't used it.
Thanks!
I’m trying to follow this tutorial, but they don’t provide how to correctly invoke the lambda from the AWS CLI
I’m using:
aws lambda invoke --function-name clj-hello --payload '{"body": "Will"}' /dev/stdout
But I get back:
{"errorMessage":"An error occurred during JSON parsing","errorType":"java.lang.RuntimeException","stackTrace":[],"cause":{"errorMessage":"com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: lambdainternal.util.NativeMemoryAsInputStream@4516af24; line: 1, column: 1]"
Does anyone know the expected shape of the JSON payload given:
(ns hello
(:gen-class
:methods [^:static [handler [String] String]]))
(defn -handler [s]
(str "Hello " s "!"))
try returning JSON formatted string from the -handler
(defn -handler [s] s)
?
for example
Same error
I technically uploaded:
(defn -handler [s]
(str "Hello " s "!")
s)
I am wondering why it is complaining about JSON at all.
I've hit that before. It has to do with the signature of your Java lambda fn. I remember having to switch to the input/output stream signature. Googling that exception gives you some answers IIRC.
Huh, I thought AWS could infer what to parse given the handler signature
(ns hello
(:gen-class
:methods [^:static [handler [String] String]]))
The handler is expecting a pojo.
I have done handlers always like this.
I’m not going through the API Gateway
➜ aws lambda invoke --function-name clj-helloooo --payload 'Will' /dev/stdout
An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Unrecognized token 'Will': was expecting ('true', 'false' or 'null')
at [Source: (byte[])"Will"; line: 1, column: 9]
I do the same as @jsyrjala. More general that way too.
Okay, I’ll try that
Thanks y’all
And you can use also non-json messages like that.
Quick question/poll: Which would you all choose for a lambda with an avg response time <300ms, CLJ (with or without heartbeat warmer) or CLJS?
don't focus on time -- it all depends on what it's doing. You will find a richer ecosystem of libraries on the JVM imho, and the warm speeds will be faster
Would a Lumo runtime have a faster startup time than a CLJS fn compiled to JS?
.......
I’m just curious
focusing on startup time is misguided
but super popular 😉