Skip to content

Commit

Permalink
enforcing aws client requests which will retry non-200 requests (#75)
Browse files Browse the repository at this point in the history
we are seeing some 401 in sts get-caller-identity for us-west-2
which might be related to iam being central so us-east-1
so a few retries might help the request to suceed
  • Loading branch information
miki725 authored Aug 9, 2024
1 parent 1f7f51e commit 3d2901d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 7 additions & 1 deletion nimutils/awsclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,10 @@ proc request*(client: var AwsClient, params: Table, headers: HttpHeaders = newHt
client.httpClient.headers.table, client.scope)
client.httpClient.headers.add("Authorization", auth)

return client.httpClient.safeRequest(url, action, payload, headers=headers)
return client.httpClient.safeRequest(
url,
action,
payload,
headers=headers,
only2xx=true,
)
5 changes: 1 addition & 4 deletions nimutils/sinks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ proc s3SinkOut(msg: string, cfg: SinkConfig, t: Topic, ignored: StringTable) =
newPath = joinPath(state.objPath, newTail)
response = client.put_object(state.bucket, newPath, msg)

if not response.code.is2xx():
raise newException(ValueError, response.status & ": " & response.body())
else:
cfg.iolog(t, "Post to: " & newPath & "; response = " & response.status)
cfg.iolog(t, "Post to: " & newPath & "; response = " & response.status)

proc httpHeaders(cfg: SinkConfig): HttpHeaders =
var
Expand Down
2 changes: 0 additions & 2 deletions nimutils/stsclient.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ proc getCallerIdentity*(self: var StsClient): StsCallerIdentity =
("Content-Type", "application/x-www-form-urlencoded"),
("Accept", "application/json"),
]))
if res.code != Http200:
raise newException(ValueError, res.status)
let
jsonResponse = parseJson(res.body())
identity = jsonResponse["GetCallerIdentityResponse"]["GetCallerIdentityResult"]
Expand Down

0 comments on commit 3d2901d

Please sign in to comment.