aws

http://status.aws.amazon.com/ https://www.expeditedssl.com/aws-in-plain-english
mruzekw 2019-10-24T17:21:39.077300Z

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

alexmiller 2019-10-24T17:22:51.077900Z

they are very different approaches

alexmiller 2019-10-24T17:23:28.078600Z

amazonica is a clojure wrapper for the Java SDK

alexmiller 2019-10-24T17:24:14.079400Z

aws-api is a data-oriented and data-driven Clojure API directly to the AWS http api

mruzekw 2019-10-24T17:27:05.082Z

Would it be possible to adapt aws-api for cljs?

alexmiller 2019-10-24T17:27:22.082300Z

that has been discussed

alexmiller 2019-10-24T17:27:35.082700Z

I don't know the status of it

mruzekw 2019-10-24T17:27:38.082800Z

My use case would be using CLJS for AWS lambda

alexmiller 2019-10-24T17:27:51.083100Z

https://github.com/cognitect-labs/aws-api/issues/11

alexmiller 2019-10-24T17:28:00.083500Z

^^ the issue to follow

mruzekw 2019-10-24T17:28:05.083900Z

Nice, thanks

mruzekw 2019-10-24T17:28:38.084500Z

Would it just take converting clj files to cljc?

mruzekw 2019-10-24T17:28:42.084700Z

“just”

alexmiller 2019-10-24T17:28:49.084900Z

no

alexmiller 2019-10-24T17:29:19.085800Z

you would need a cljs http library instead (maybe other things too, I don't know)

mruzekw 2019-10-24T17:29:28.086200Z

Makes sense

alexmiller 2019-10-24T17:30:12.087300Z

conceptually there is no reason that can't work afaik

ghadi 2019-10-24T17:30:50.088200Z

we are making moves towards being able to being able to support cljs but cljs isn’t in the short term milestones

mruzekw 2019-10-24T17:31:25.088800Z

Is there an existing cljs solution for the AWS api?

alexmiller 2019-10-24T17:31:36.089Z

I don't think amazonica does that for cljs

mruzekw 2019-10-24T17:31:48.089400Z

Maybe interop with aws-sdk-js?

alexmiller 2019-10-24T17:32:04.089800Z

seems like that would be the obvious thing to do

ghadi 2019-10-24T17:32:09.090Z

Apart from http there are also signing routines that need porting to cljs

mruzekw 2019-10-24T17:32:33.090900Z

Is that done on a clj reader level or a namespace level?

ghadi 2019-10-24T17:32:59.091600Z

Signing routines are not terribly complicated, but we’re trying to move forward everything compatibly

ghadi 2019-10-24T17:33:41.092300Z

And that can be tricky

ghadi 2019-10-24T17:34:26.093200Z

@mruzekw what makes you interested in cljs over clj?

mruzekw 2019-10-24T17:34:47.093700Z

I plan on using AWS Lambda

mruzekw 2019-10-24T17:35:01.094100Z

Though I’m not opposed to using CLJ with GraalVM

ghadi 2019-10-24T17:35:32.094900Z

GraalVM is not possible with these dependencies AFAIK

ghadi 2019-10-24T17:35:41.095200Z

Native-image, that is

ghadi 2019-10-24T17:36:48.096500Z

What is your SLA for startup time?

mruzekw 2019-10-24T17:38:06.097200Z

I mean, I’d like to get cold start to <= 500ms and warm <=200ms

ghadi 2019-10-24T17:41:23.098700Z

What sorts of dependencies are you interested in running within lambda? Sorry for the 20 questions, doing research :)

mruzekw 2019-10-24T17:42:09.098900Z

haha no worries

mruzekw 2019-10-24T17:43:03.100100Z

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

mruzekw 2019-10-24T17:43:46.101300Z

This is just for now. I could see a use for a queue component

jsyrjala 2019-10-24T17:43:54.101500Z

One thing to consider is if you need to run lambdas in VPC, which would increase the cold start time

mruzekw 2019-10-24T17:44:33.101800Z

Hmm good to know, VPC restricts public access?

jsyrjala 2019-10-24T17:45:40.102600Z

It allows lambda to talk to services that are inside a VPC that are not accessible from outside

mruzekw 2019-10-24T17:46:07.102900Z

Okay, will have to think that through

mruzekw 2019-10-24T17:46:33.103900Z

Do you know how much ms on average accessing through a VPC is?

jsyrjala 2019-10-24T17:48:54.105900Z

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.

mruzekw 2019-10-24T17:49:40.106600Z

Wow a few seconds is significant

mruzekw 2019-10-24T17:51:12.107Z

933 ms is better but not great

mruzekw 2019-10-24T17:51:36.107200Z

But I guess that’s just on cold

mruzekw 2019-10-24T17:52:40.107500Z

Is there a good doc ref for the AWS HTTP level API?

mruzekw 2019-10-24T17:52:45.107700Z

All I can find are the SDK docs

Joe Lane 2019-10-24T17:53:06.108Z

That is what aws-api solves for you.

Joe Lane 2019-10-24T17:53:51.108600Z

basically there is a json based datastructure for all the api's but I'm not aware of a complete doc reference.

mruzekw 2019-10-24T17:54:13.108800Z

Hmm alright

mruzekw 2019-10-24T17:55:20.109300Z

> 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.

mruzekw 2019-10-24T17:55:23.109500Z

Gotcha

Joe Lane 2019-10-24T17:55:35.109800Z

I prefer the aws-api because then i'm not stuck using builders like the java sdk

mruzekw 2019-10-24T17:56:22.110500Z

query.firstParam().secondParam().build() type API?

Joe Lane 2019-10-24T17:56:51.110800Z

One word, RequestBuilder.

mruzekw 2019-10-24T18:00:03.113100Z

Does aws-api take outside PRs?

Joe Lane 2019-10-24T18:00:13.113300Z

No, but they take issues

mruzekw 2019-10-24T18:00:18.113600Z

Kk

mruzekw 2019-10-24T18:00:58.114Z

I may just use aws/aws-sdk-js in the mean time

ghadi 2019-10-24T18:01:54.115500Z

Editorial: I’m all for faster startup times, but cold start is talked about way too much without surrounding use-cases

ghadi 2019-10-24T18:02:52.116500Z

(That’s why I’m probing for details)

mruzekw 2019-10-24T18:02:58.116800Z

Well I’m hoping to have lambdas that serve API responses

mruzekw 2019-10-24T18:03:04.117100Z

Servicing a frontend SPA

mruzekw 2019-10-24T18:03:14.117400Z

I’d like the user operations to be quick

mruzekw 2019-10-24T18:03:19.117700Z

Thus below 1s

alexmiller 2019-10-24T18:03:33.118100Z

if people are using it, then things aren't cold right?

mruzekw 2019-10-24T18:03:53.118800Z

Right, within a timeout

mruzekw 2019-10-24T18:04:57.120300Z

If people don’t use it for say 10 mins it destructs

Joe Lane 2019-10-24T18:04:57.120400Z

Set a cloudwatch event to ping your stuff every n minutes. Then it's never cold.

mruzekw 2019-10-24T18:05:08.120600Z

Sure, not a bad idea

mruzekw 2019-10-24T18:05:24.121200Z

It doesn’t cost to keep a fn warm?

Joe Lane 2019-10-24T18:05:29.121500Z

nope

mruzekw 2019-10-24T18:05:32.121700Z

Nice

jsyrjala 2019-10-24T18:05:48.122Z

That keeps one lambda instance warm, you’ll get cold starts if you happen to need more than one simultaneously.

Joe Lane 2019-10-24T18:06:03.122300Z

you can invoke a lambda to invoke your lambdas

mruzekw 2019-10-24T18:06:13.122600Z

Dynamically?

mruzekw 2019-10-24T18:06:24.123Z

Like it knows which are warm already?

Joe Lane 2019-10-24T18:07:39.124100Z

This coldstart thing is almost never an issue unless you have a thundering herd scenario.

Joe Lane 2019-10-24T18:08:22.125Z

If you make a heartbeat lambda which heartbeats all your other possible lambdas then this is solved, right?

mruzekw 2019-10-24T18:09:38.125500Z

Where does the heartbeat originate?

Joe Lane 2019-10-24T18:09:47.125900Z

cloudwatch event rule

mruzekw 2019-10-24T18:09:49.126Z

I think there’s a timelimit on a running lamnda

mruzekw 2019-10-24T18:09:51.126200Z

Ohhh

mruzekw 2019-10-24T18:11:46.126400Z

https://mikhail.io/serverless/coldstarts/aws/

mruzekw 2019-10-24T18:11:56.126800Z

Last heading: > What Is The Effect Of VPC Access?

mruzekw 2019-10-24T18:12:51.127300Z

Looks like VPC only slows a cold start by about 0.1s

jsyrjala 2019-10-24T18:13:44.128100Z

That is a new feature. It used to be a lot worse.

mruzekw 2019-10-24T18:14:06.128400Z

I am grateful

jsyrjala 2019-10-24T18:14:51.128600Z

https://www.youtube.com/watch?v=GINI0T8FPD4

mruzekw 2019-10-24T18:15:42.128900Z

That’s on my list to watch

mruzekw 2019-10-24T18:15:50.129200Z

Do you have a tldr/w?

jsyrjala 2019-10-24T18:18:59.130700Z

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.

mruzekw 2019-10-24T18:19:26.131Z

Sure, matches with my research so far

mruzekw 2019-10-24T18:22:56.131500Z

Thanks for all your input all 🙏 🙂

jsyrjala 2019-10-24T18:23:34.132500Z

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.

alexmiller 2019-10-24T18:24:32.133600Z

if cold starts are your problem, then isn't the real problem no one is using your stuff?

😂 1
ghadi 2019-10-24T18:24:46.134100Z

given settings also affect how fast the code slugs are pulled down

ghadi 2019-10-24T18:24:58.134300Z

and larger code slugs => slower to pull

ghadi 2019-10-24T18:25:08.134600Z

that's partly what Lambda Layers help with

ghadi 2019-10-24T18:25:24.135Z

coldstart is but one aspect

ghadi 2019-10-24T18:25:32.135300Z

of a much larger picture

jsyrjala 2019-10-24T18:29:09.137Z

I’ve made this leiningen template to help creating lambda projects for clojure: https://github.com/jsyrjala/aws-lambda-serverless/

mruzekw 2019-10-24T20:08:22.137800Z

@jsyrjala Do you know of any other Clojure on Lambda resources?

jsyrjala 2019-10-24T20:15:18.139200Z

Can’t remember anything else that I have used.

jsyrjala 2019-10-24T20:17:01.139900Z

Mostly lambdas I have done are backend stuff where cold starts do not matter at all.

kenny 2019-10-24T20:19:36.140900Z

@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.

mruzekw 2019-10-24T20:19:57.141200Z

Thanks!

mruzekw 2019-10-24T20:43:00.141800Z

I’m trying to follow this tutorial, but they don’t provide how to correctly invoke the lambda from the AWS CLI

mruzekw 2019-10-24T20:43:27.142100Z

I’m using:

aws lambda invoke --function-name clj-hello --payload '{"body": "Will"}' /dev/stdout

mruzekw 2019-10-24T20:44:00.142400Z

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]"

mruzekw 2019-10-24T20:44:23.142900Z

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 "!"))

mruzekw 2019-10-24T20:44:38.143100Z

Tutorial: https://aws.amazon.com/blogs/compute/clojure/

jsyrjala 2019-10-24T21:01:34.144Z

try returning JSON formatted string from the -handler

mruzekw 2019-10-24T21:02:04.144300Z

(defn -handler [s] s)?

jsyrjala 2019-10-24T21:02:29.144600Z

for example

mruzekw 2019-10-24T21:04:47.145200Z

Same error

mruzekw 2019-10-24T21:06:25.146Z

I technically uploaded:

(defn -handler [s]
  (str "Hello " s "!")
  s)

jsyrjala 2019-10-24T21:07:26.146900Z

I am wondering why it is complaining about JSON at all.

kenny 2019-10-24T21:07:37.147200Z

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.

mruzekw 2019-10-24T21:08:11.147600Z

Huh, I thought AWS could infer what to parse given the handler signature

mruzekw 2019-10-24T21:08:14.147800Z

(ns hello
  (:gen-class
   :methods [^:static [handler [String] String]]))

kenny 2019-10-24T21:08:58.148400Z

The handler is expecting a pojo.

jsyrjala 2019-10-24T21:09:26.148500Z

I have done handlers always like this.

mruzekw 2019-10-24T21:09:45.149Z

I’m not going through the API Gateway

mruzekw 2019-10-24T21:09:47.149200Z

➜ 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]

kenny 2019-10-24T21:10:33.149600Z

I do the same as @jsyrjala. More general that way too.

mruzekw 2019-10-24T21:10:44.149900Z

Okay, I’ll try that

mruzekw 2019-10-24T21:10:54.150200Z

Thanks y’all

jsyrjala 2019-10-24T21:12:28.151600Z

And you can use also non-json messages like that.

mruzekw 2019-10-24T21:16:01.152800Z

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?

ghadi 2019-10-24T21:17:31.154200Z

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

👍 1
mruzekw 2019-10-24T21:23:38.155400Z

Would a Lumo runtime have a faster startup time than a CLJS fn compiled to JS?

mruzekw 2019-10-24T21:24:24.155800Z

ala https://github.com/grav/aws-lumo-cljs-runtime

ghadi 2019-10-24T21:24:24.155900Z

.......

😂 1
mruzekw 2019-10-24T21:24:37.156500Z

I’m just curious

ghadi 2019-10-24T21:24:40.156600Z

focusing on startup time is misguided

ghadi 2019-10-24T21:24:56.157Z

but super popular 😉