Fork me on GitHub
#aws
<
2020-07-16
>
bamarco14:07:00

Does anyone know why the following does not actually send a response to wscat? I have tries all kinds of things for :Data which is supposed to be a blob including (a json string, a json smile, a .getBytes of json string, a plain test string, and the object shown below)

(aws/invoke (aws/client {:api :apigatewaymanagementapi})
      {:op :PostToConnection
       :request {:Data {"action" "pong"}, :ConnectionId id}})

bamarco14:07:31

I get no errors at all

ghadi14:07:43

call (aws/doc client :PostToConnection)

bamarco14:07:21

PostToConnection
:op :PostToConnection
:request
{:Data blob, :ConnectionId string}
:required
[:ConnectionId :Data]
:response
nil
Sends the provided data to the specified connection.

ghadi14:07:12

{"action" "pong"} is not a blob

ghadi14:07:15

(aws/validate-requests client true) then redo your request

bamarco15:07:27

is aws/validate-requests something I call on the client that acts like a validate-requests! or do I get a different client back. I tried the version where I get a client back, but it said the api was not implemented so I am assuming I just need to call it and it will change the state of the client. As far as blobs go, I can't figure out how to make a blob that wscat will understand, I just tried

(aws/invoke gw
      {:op :PostToConnection
       :request {:Data (bytes (byte-array (map (comp byte int) (json/generate-string {:action :pong})))), :ConnectionId id}})
and
(aws/invoke gw
      {:op :PostToConnection
       :request {:Data (bytes (byte-array (map (comp byte int) "test"))), :ConnectionId id}})

ghadi15:07:07

create the client, def it, call validate-requests on it, then use the client and it should throw a spec error when you give it an invalid blob

bamarco15:07:16

I will test giving it something bad now to make sure it throws errors. Both those do not give an error on the amazon side

bamarco15:07:51

Okay so I get no errors from the following for some reason:

(aws/validate-requests gw true)
(aws/invoke gw
  {:op :PostToConnection
   :request {:VeryBad {"a" "bad"}}})

bamarco15:07:52

will it be in the response to invoke maybe rather than thrown?

ghadi15:07:49

it might not complain if :Data is optional

ghadi15:07:03

give it {:Data 42} and see what happens

bamarco16:07:37

It doesn't throw, but rather returns problems from the invocation call. After clearing up errors I am left with

(aws/invoke gw
                     {:op :PostToConnection
                      :request {:Data (byte-array (map (comp byte int) (json/generate-string {:action :pong})))
                                :ConnectionId id}})
Which produces:
"#:cognitect.anomalies{:category :cognitect.anomalies/not-found, :message \": No address associated with hostname\"}"
This leads me to believe {:api :apigatewaymanagementapi} does not detect which deployment I am running, dev in this case. Not sure where I would input this information or how to check if it does detect those things.

bamarco17:07:00

I was following https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-how-to-call-websocket-api-connections.html when I decided to try and use apigatewaymanagementapi directly rather than create my own http posts.

bamarco17:07:54

@joe.lane no! that is so much more specific to what i am trying to do. Thanks! Also thanks @ghadi

3