aws

http://status.aws.amazon.com/ https://www.expeditedssl.com/aws-in-plain-english
2019-11-15T05:16:35.177400Z

@mruzekw you may interested in https://github.com/stediinc/cdk-clj.

kulminaator 2019-11-15T14:40:50.179400Z

Trying to do S3 listing from within of an aws lambda fails for me with aws/api and aws/s3

kulminaator 2019-11-15T14:42:42.179500Z

{:cognitect.anomalies/category :cognitect.anomalies/fault, :cognitect.anomalies/message java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;, :cognitect.http-client/throwable #error {
 :cause java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
 :via
 [{:type java.lang.NoSuchMethodError
   :message java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
   :at [cognitect.http_client$empty_bbuf invokeStatic http_client.clj 37]}]
 :trace
 [[cognitect.http_client$empty_bbuf invokeStatic http_client.clj 37]
  [cognitect.http_client$empty_bbuf invoke http_client.clj 34]
  [cognitect.http_client$on_content$fn__10264 invoke http_client.clj 140]
  [clojure.core$update invokeStatic core.clj 6196]
  [clojure.core$update invoke core.clj 6188]
  [cognitect.http_client$on_content invokeStatic http_client.clj 139]
  [cognitect.http_client$on_content invoke http_client.clj 136]
  [clojure.lang.Atom swap Atom.java 51]

kulminaator 2019-11-15T14:43:16.179700Z

;; code starting like

(let [s3-listing (aws/invoke s3 {:op :ListObjectsV2 :request
                                   {:Bucket bucket-name
                                    :Prefix files-prefix}})
        s3-files (map :Key (:Contents s3-listing))]
    (println s3-listing)

kulminaator 2019-11-15T14:44:20.181300Z

Any advice is welcome, some parts of the internet suggest a jdk version issue, aws lambda is running java8

alexmiller 2019-11-15T14:52:06.181400Z

which JDK?

alexmiller 2019-11-15T14:52:51.181600Z

and you are aot'ing

alexmiller 2019-11-15T14:52:58.181800Z

and if so with what jdk

kulminaator 2019-11-15T15:02:51.182Z

Will report a little later

kulminaator 2019-11-15T16:00:01.182200Z

I was compiling with leiningen on java11 openjdk, and Amazon is running java8 openjdk for java lambdas

kulminaator 2019-11-15T16:00:44.182400Z

Once I convinced leiningen to run with java8 for uberjar build the problem seemed to go away

alexmiller 2019-11-15T16:11:55.182600Z

yeah, that's what I would have recommended

alexmiller 2019-11-15T16:12:53.182800Z

there have been some changes in the jdk that affect the compiled method invocation here. I don't remember the details but it is pretty subtle

kenny 2019-11-15T16:56:40.183300Z

The aws-api readme says: > specs which are generated from the source descriptions There's no obvious documentation on how to use these. How do I access these generated specs?

kenny 2019-11-15T16:59:17.183800Z

Ah found it. You're supposed to use response-spec-key.

kenny 2019-11-15T17:01:16.184300Z

How come enum values are not enumerated in the generated specs?

kenny 2019-11-15T17:02:26.184700Z

The actual AWS API reference docs seem to have access to enum values.

ghadi 2019-11-15T17:32:30.185200Z

(s/def :cognitect.aws.kinesis/ConsumerStatus #{"DELETING" "CREATING" "ACTIVE"})
enums are there

ghadi 2019-11-15T17:33:00.185900Z

@kenny can you post stuff you tried, whether you were successful or not?

kenny 2019-11-15T17:33:41.186300Z

Not all of them are like that:

(s/def :cognitect.aws.workspaces/WorkspaceState string?)
Reference docs: https://docs.aws.amazon.com/workspaces/latest/api/API_Workspace.html?shortFooter=true

kenny 2019-11-15T17:34:09.186600Z

> Valid Values: PENDING | AVAILABLE | IMPAIRED | UNHEALTHY | REBOOTING | STARTING | REBUILDING | RESTORING | MAINTENANCE | ADMIN_MAINTENANCE | TERMINATING | TERMINATED | SUSPENDED | UPDATING | STOPPING | STOPPED | ERROR

ghadi 2019-11-15T17:34:26.187Z

looking -- what's the mvn coordinate you're using?

kenny 2019-11-15T17:34:34.187200Z

com.cognitect.aws/workspaces {:mvn/version "758.2.549.0"}

ghadi 2019-11-15T17:34:45.187700Z

thx

kenny 2019-11-15T17:35:51.188Z

Just tried the latest 770.2.568.0 and same thing.

kenny 2019-11-15T17:38:00.188200Z

Same thing for (s/def :cognitect.aws.workspaces/ConnectionState string?)

ghadi 2019-11-15T17:39:10.188800Z

investigating

1
kenny 2019-11-15T17:40:15.189600Z

The generators for these specs also don't work.

(gen/generate (s/gen :cognitect.aws.workspaces.Workspace/DirectoryId))
Execution error (ExceptionInfo) at clojure.test.check.generators/fn (generators.cljc:435).
Couldn't satisfy such-that predicate after 100 tries.
That's a bit harder to solve given the spec is a regex.

ghadi 2019-11-15T17:41:55.190200Z

regex specs is a known problem that @dchelimsky is working on

ghadi 2019-11-15T17:42:09.190600Z

not all regexes are invertible, even if we use a library like test.chuck

ghadi 2019-11-15T17:42:41.191400Z

i'm looking into why (s/def :cognitect.aws.workspaces/ConnectionState string?) is not an enum

kenny 2019-11-15T17:42:48.191700Z

True. Seems like test.chuck may be good enough for most/all of the aws cases though?

ghadi 2019-11-15T17:43:35.192500Z

you would think but @dchelimsky tested it and it's about 50/50 from what I recall

ghadi 2019-11-15T17:43:50.192900Z

some of the regexes AWS has are truly bizarre

kenny 2019-11-15T17:44:02.193100Z

Not surprised haha

kenny 2019-11-15T17:48:27.194300Z

test.check doesn't work on the DirectoryId regex. Oh well.

ghadi 2019-11-15T17:51:28.194700Z

@kenny it turns out that the enum excludes values that the api actually responds to

ghadi 2019-11-15T17:51:51.195100Z

we found that to be the case on some APIs

kenny 2019-11-15T17:52:29.195500Z

Geez. Does the enum def match the api doc reference?

ghadi 2019-11-15T17:52:44.195700Z

which enum def?

kenny 2019-11-15T17:52:55.195900Z

The one you looked at

kenny 2019-11-15T17:53:20.196500Z

ConnectionState

ghadi 2019-11-15T17:53:27.196700Z

i didn't look at a specific one, I just found out the history for the change

ghadi 2019-11-15T17:53:48.197100Z

it probably matches in 95% of the cases, if I were to guess

kenny 2019-11-15T17:54:00.197600Z

How do you know it doesn't match?

ghadi 2019-11-15T17:54:09.197800Z

matching meaning the API documentation (non-canonical) and the service descriptor (non-canonical)

ghadi 2019-11-15T17:54:23.198200Z

the truth is what the API accepts and returns

ghadi 2019-11-15T17:54:36.198500Z

which might not be in sync with descriptors or documentation

ghadi 2019-11-15T17:54:55.198900Z

these specs are mechanically generated from json descriptors

kenny 2019-11-15T17:55:14.199300Z

The only was you'd know "the truth" is by executing API calls, right?

ghadi 2019-11-15T17:55:18.199500Z

yeah

kenny 2019-11-15T17:55:40.200400Z

So these specs have been manually overridden?

ghadi 2019-11-15T17:56:02.200800Z

If I were to guess what happened: someone tried to hit an API with the library's validation turned on, and a value was rejected because it wasn't in the enum spec

ghadi 2019-11-15T17:56:08.201Z

enums are closed specs

ghadi 2019-11-15T17:57:06.202300Z

(value rejected by the library's validation)

ghadi 2019-11-15T17:57:14.202700Z

not by the service itself

kenny 2019-11-15T17:57:33.203100Z

Interesting. A bit surprised someone else is using Clojure & WorkSpaces haha. So then you guys must be storing which specs do not match and overriding with the "open" enum -- string?.

ghadi 2019-11-15T17:57:53.203400Z

i never said anything about Workspaces

ghadi 2019-11-15T17:58:35.204200Z

it's a general issue we hit somewhere else, that made us re-examine how we emit specs

kenny 2019-11-15T17:58:52.204500Z

So all enums are open?

ghadi 2019-11-15T18:00:07.205700Z

are enums in AWS specced as string? ?

kenny 2019-11-15T18:00:33.205900Z

But this one isn't? https://clojurians.slack.com/archives/C09N0H1RB/p1573839150185200

ghadi 2019-11-15T18:01:23.206500Z

yeah that might be a stale artifact, I'll confirm on a more recent mvn

kenny 2019-11-15T18:01:58.207200Z

So all AWS enums are supposed to be specced as string??

ghadi 2019-11-15T18:02:56.207400Z

(s/def :cognitect.aws.kinesis/ConsumerStatus string?)

ghadi 2019-11-15T18:03:00.207700Z

on latest ^

kenny 2019-11-15T18:04:35.209400Z

I understand. It's kinda a tricky situation. I'm planning to have functions that operate over certain AWS properties. Having generators generate relevant values is important. Seems like the enum values should be worked into the generated generators.

ghadi 2019-11-15T18:06:18.210600Z

understood

kenny 2019-11-15T18:06:59.211200Z

If the gens for things like ConsumerStatus always generate a random string it will not hit all the code paths, making the gen test bad. For now I can do something like this for all the enum specs:

(s/def :workspace-info/State
  (s/with-gen
    :cognitect.aws.workspaces/WorkspaceState
    #(gen/one-of [(s/gen #{"PENDING"
                           "AVAILABLE"
                           "IMPAIRED"
                           "UNHEALTHY"
                           "REBOOTING"
                           "STARTING"
                           "REBUILDING"
                           "RESTORING"
                           "MAINTENANCE"
                           "ADMIN_MAINTENANCE"
                           "TERMINATING"
                           "TERMINATED"
                           "SUSPENDED"
                           "UPDATING"
                           "STOPPING"
                           "STOPPED"
                           "ERROR"})
                  (s/gen string?)])))
It'd be nice to have something like that build in.

kenny 2019-11-15T18:08:53.212100Z

Also would be great to have a note in the readme or, even better, next to the enum specs noting why it is specced as an open enum.

ghadi 2019-11-15T18:09:56.212500Z

can you assist us by capturing a github issue with details?

ghadi 2019-11-15T18:10:20.213Z

the concerns are documentation/discovery of enums, and associated gen of enum specs

kenny 2019-11-15T18:18:50.213200Z

Sure

ghadi 2019-11-15T18:20:00.213400Z

thanks!

2019-11-15T18:47:00.214100Z

@kenny side note: you'll get better feedback (s/describe and s/explain) if you use the s/spec macro with :gen than the s/with-gen function.

kenny 2019-11-15T21:25:06.214300Z

Weird. That doesn't seem like the intended use for s/spec.