Fork me on GitHub
#aws
<
2022-05-06
>
kouvas09:05:30

Hi. I am trying to set a filter on an sns subscription but i get the following error message. The doc says :Attributes must be map of sting, string.

:Message "Invalid parameter: Attributes Reason: FilterPolicy: \"test\" must be an object or an array
                                   at [Source: (String)\"{\"test\":\"this\"}\"; line: 1, column: 15]",
(aws/invoke aws-client {:op :Subscribe
                          :request {:TopicArn topic
                                    :Protocol "sqs"
                                    :Endpoint "arn:aws:sqs:eu-west-1:44444:queueue"
                                    :ReturnSubscriptionArn true
                                    :Attributes {"FilterPolicy" (clojure.data.json/json-str {"test" "this"})}}})

                   

jjttjj11:05:09

Haven't done anything with sns filter policies but based on https://docs.aws.amazon.com/sns/latest/dg/example-filter-policies.html it seems like you need the values in your Json maps to be sequential, representing sets of values you'll accept. So in your case the Json should be

{"test":["test"]}

jjttjj12:05:35

Regarding https://github.com/cognitect-labs/aws-api Assuming things like region/creds are constant throughout my app (and/or use defaults), is it reasonable to do something like:

(def get-client (memoize (fn [api] (aws/client {:api api}))))

(defn get-object [bucket key]
  (aws/invoke (get-client :s3)
    {:op      :GetObject
     :request {:Bucket bucket
               :Key    key}}))
or even:
(defn invoke [api op-map]
  (aws/invoke (get-client api) op-map))

ghadi13:05:11

clients can be memoized but I'd always pass them explicitly to functions wrappers like get-object above don't add value (they're just taking positional syntax, making a map, then calling invoke) since there's only one function to invoke clients aws/invoke, such wrappers all have the same shape: form a request, then invoke it. Instead, make functions that simply form the request.

jjttjj13:05:46

Just curious, why always explicitly pass the clients?

ghadi13:05:15

global state sucks

ghadi13:05:32

args > global state

jjttjj13:05:58

Oh yeah makes sense 🙂