Created
August 9, 2024 04:07
-
-
Save jamesdavidson/d9fd61ab3d843bfcd8afec776edf5758 to your computer and use it in GitHub Desktop.
Playing around with making API calls to Amazon S3 from Clojure CLR using the AwsSignatureVersion4 library from Nuget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; <PackageReference Include="AwsSignatureVersion4" Version="4.0.1" /> | |
(ns get_from_s3 | |
(:import [Amazon.Runtime EnvironmentVariablesAWSCredentials SessionAWSCredentials] | |
[System.Net.Http HttpClient GetAsyncExtensions HttpCompletionOption] | |
[System Uri]) | |
;(:use clojure.pprint clojure.repl clojure.reflect) | |
(:require [clojure.clr.io :as io])) | |
;(assembly-load "AWSSDK.Core") | |
;(assembly-load "AwsSignatureVersion4") | |
(def client (new HttpClient)) | |
(def creds (new EnvironmentVariablesAWSCredentials)) ; or new SessionAWSCredentials(key,secret,token) | |
(def obj-uri (new Uri "https://batch-jobs-dev.s3.ap-southeast-1.amazonaws.com/manifests/manifest-1234.csv.gz")) | |
(with-open [os (io/output-stream "output.csv.gz")] | |
(let [res (.Result (GetAsyncExtensions/GetAsync client obj-uri HttpCompletionOption/ResponseHeadersRead "ap-southeast-1" "s3" creds))] | |
(-> res .Content (.CopyToAsync os) .Result))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment