Fork me on GitHub
#babashka
<
2023-09-14
>
Varghiz clj03:09:34

Hi, I'm getting the below error when I tried to connect to s3 bucket and fetch the document from babashka.. I'm using

{:cognitect.anomalies/category :cognitect.anomalies/fault, :cognitect.anomalies/message "java.io.UncheckedIOException: java.io.IOException: Invalid redirection", :com.grzm.awyeah.http-client/throwable #error {
 :cause "Invalid redirection"
 :via
 [{:type java.util.concurrent.CompletionException
   :message "java.io.UncheckedIOException: java.io.IOException: Invalid redirection"
   :at [java.util.concurrent.CompletableFuture encodeRelay "CompletableFuture.java" 368]}
  {:type java.io.UncheckedIOException
   :message "java.io.IOException: Invalid redirection"
   :at [jdk.internal.net.http.RedirectFilter lambda$getRedirectedURI$0 "RedirectFilter.java" 136]}
  {:type java.io.IOException
   :message "Invalid redirection"
   :at [jdk.internal.net.http.RedirectFilter lambda$getRedirectedURI$0 "RedirectFilter.java" 136]}]

Varghiz clj03:09:14

I'm trying to print the response of the below code and I get the above error

(-> (aws/invoke s3 {:op :GetObject :request {:Bucket "<bucket name>" :Key "<the file name>"}})
     prn)

Varghiz clj03:09:39

what am I doing wrong?? Please help! additional note: I'm able to list all the buckets within the S3.. just that getting this error when I try to download the document

borkdude09:09:26

I'm not sure how to debug this, I don't usually do stuff with AWS. Have you tried the regular cognitect aws-api library on the JVM to see if the same issue happens over there?

1
borkdude09:09:52

Perhaps @U0EHU1800 can shed some light on this as well, if he has time or @U7ERLH6JX since he does stuff with AWS too

Daniel Gerson09:09:43

@U04LJ76K6BY Have you tried in Clojure with https://github.com/cognitect-labs/aws-api and do you get the same error?

lispyclouds10:09:12

seems to work for me with a test bucket and object with awyeah api. tested with the versions mentioned in the readme. could you tell us more about the versions being used, if there is any special things about the key or path etc @U04LJ76K6BY?

lispyclouds10:09:12

there seems to be a redirect happening in your call somehow, not sure how to reproduce that. im suspecting something is up with the path, spaces or something which is confusing the redirect

borkdude10:09:48

could be a proxy maybe?

1
Varghiz clj10:09:23

Thank you @U04V15CAJ, @U7ERLH6JX and @U03B2SRNYTY.. @U03B2SRNYTY, I'll try aws-api but behind the scene awyeah-api calls aws-api for S3 related functionalities.. @U7ERLH6JX @U04V15CAJ, I was thinking the same.. it is not that this code didn't work, it did work till yesterday but then I've been getting this issue.. the versions I'm using are the below..

lispyclouds10:09:49

are you using an SSO provider by any chance?

borkdude10:09:02

@U04LJ76K6BY This isn't true, awyeah-api doesn't call aws-api behind the scenes, it is a re-implementation, but it does use the endpoint and API data from the regular Clojure lib. Please try JVM + aws-api (cognitect) as has been recommended two times before ;)

Varghiz clj11:09:39

@U04V15CAJ,, sorry.. I wanted to edit say I think it uses.. you caught me before that.. sure @U04V15CAJ, I'll try that. @U7ERLH6JX, yes.. but we created an iam user and use that to connect to the bucket

lispyclouds11:09:40

i think that the API keys of the user has expired and its possibly trying to redirect to the SSO landing page

lispyclouds11:09:11

does it work with the AWS CLI? using the same creds?

Varghiz clj11:09:30

the key is not expired.. I don't know if token generated by awyeah-api is expired and it is trying to redirect.. if yes, how do I refresh the token? and also, as I mentioned earlier, (-> (aws/invoke s3 {:op :ListBuckets}) <= this one works.. if the key is expired, wont this fail?

lispyclouds11:09:11

right makes sense, can you also make sure the role has the required IAM permissions are there too? can you try this with the AWS CLI?

lispyclouds11:09:45

even before you try with the JVM and aws-api, i suspect something has changed externally

Varghiz clj11:09:57

@U04V15CAJ @U03B2SRNYTY, Getting a different error when u used jvm + cognitect aws-api

Varghiz clj11:09:41

@U04V15CAJ, @U03B2SRNYTY, @U7ERLH6JX It worked with jvm + cognitect aws-api and found an issue with the incorrect region.. I tried babashka + awyeah+api and it worked as well.. Thank you so much .. I wish awyeah-api has friendly error as cognitect had!!

👍 2
1
borkdude11:09:38

incorrect region, I've heard this several times ;)

😄 1
lispyclouds11:09:56

in my experience too when i hit cryptic errors like this, i try the AWS CLI first, that narrows it down the fastest

Varghiz clj11:09:17

when I did as you (@U04V15CAJ) and Daniel (@U03B2SRNYTY) suggested, I could see the real issue.. as I said, I wish awyeah-api returned the same..

Varghiz clj11:09:38

will do @U7ERLH6JX.. appreciate this help.. all of you!!

lispyclouds11:09:53

9/10 times it’s one of the 5 billion AWS knobs that’s the real thing, not so much the code 😅

Varghiz clj14:09:25

lol.. btw, the weird thing is that the s3 buckets are global.. if that is the case, why would region matter is something I don't understand

lispyclouds14:09:44

buckets are region specific, you need to tell that when you create them for example:

lispyclouds14:09:52

this is to reduce latency of objects depending on where the access is from. the objects dont leave the region they are created in

👍 1
w08r18:09:05

I think AWS have changed something recently which makes some sdks more sensitive to region. Believe it may have something to do with dualstack endpoints but haven't had a proper chance to dig in yet. Boto3 (python) based stuff can be coerced into working by setting this dualstack endpoint option. (see https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html). Not sure if an equivalent exists in the java sdk and/or any thing in clojure.

grzm18:09:28

There are differences between aws-api and awyeah-api as to how the AWS http requests are generated and sent: awyeah-api uses the java.net.http.HttpClient while aws-api uses one based on the jetty client. I believe there’s at least one legitimate bug in awyeah-api related to this; I just haven’t gotten around to investigating it.

grzm18:09:39

The pieces that awyeah-api uses of aws-api are the individual service definitions, which are essentially just data transformation definitions, not code.

Daniel Gerson23:09:07

Glad Borkdude's suggestion helped. Didn't see his prior comment when I posted 😅

mmer09:09:27

Hi, I have a bb.edn with 57 tasks and I notice that the time to run a task has a delay before it runs. Functionally it runs, just a noticeable wait at the start. Is this a function of the number of tasks?

borkdude09:09:40

"it depends" ™️

™️ 1
borkdude09:09:49

not possible to say without sharing your project

mmer09:09:33

You are right it might be the load I have in the :init - I had forgotten about that part.

1
borkdude10:09:15

yep, could very well be. You could wrap your init block with (time ..) to see if that's the culprit. Sometimes lazy loading namespaces could help too, using requiring-resolve. Time could be spent loading namespaces using :requires

mmer10:09:04

I suspect it is the :require.

borkdude10:09:44

if there are expensive requires in there, replace them as follows:

(let [my-fn (requiring-resolve 'expensive.namespace/my-fn)]
  (my-fn ...))

danm10:09:08

I want my bb script to spit out some URLs the user can make use of into a little report. I can see babashka/curl.clj has a private url-encode method, which internally uses java.net.URLEncode, but that coverts data to form mime format, which means things like spaces get converted to +, instead of %20. Is there any lib included in babashka that I could use to convert a string that might contain spaces into an actual URL rather than form data?

borkdude10:09:31

(java.net.URLEncoder/encode unencoded "UTF-8")

borkdude10:09:48

oh sorry, I didn't read closely enough, you already had that

borkdude10:09:24

then I don't understand your question. Please give an example

danm10:09:24

(URLEncoder/encode "string with spaces" "UTF-8")
=> "string+with+spaces"
I need %20

danm10:09:22

From the docs > for converting a String to the application/x-www-form-urlencoded MIME format I'm not sure if anything else is different in that lib...

danm10:09:08

To what you'd normally expect in a URL. I'm unclear on why space ended up as + when everything else uses %20. From reading up it might be a very old version of the format?

danm10:09:55

I can do that no worries, but I'm worried there might be other character differences that mean it breaks that my tests don't cover

danm11:09:57

😆 Good shout!