ударяя S3 ведро aws лямбда в clojure - PullRequest
0 голосов
/ 23 апреля 2020

У меня есть индекс. html в моем s3, который просто говорит: <h1>hello world</h1>

моя лямбда выглядит так:

(def s3 (aws/client {:api :s3}))
(def file (aws/invoke s3 {:op :GetObject :request {:Bucket "my-bucket" :Key "index.html"}}))

(defn handle-event [event]
  (pprint event)
  {
   "statusCode"        200,
   "statusDescription" "200 OK"
   "isBase64Encoded"   false
   "headers"           {
                        "Content-Type" "text/html"}

   "body" (slurp (:Body file))})




(defn key->keyword [key-string]
  (-> key-string
      (st/replace #"([a-z])([A-Z])" "$1-$2")
      (st/replace #"([A-Z]+)([A-Z])" "$1-$2")
      (st/lower-case)
      (keyword)))

(defn -handleRequest [this is os context]
  (let [w (io/writer os)]
    (-> (json/read (io/reader is) :key-fn key->keyword)
        (handle-event)
        (json/write w))
    (.flush w)))

, когда я запускаю (handle-request {}) в ответе I get

=>{"statusCode" 200,
 "statusDescription" "200 OK",
 "isBase64Encoded" false,
 "headers" {"Content-Type" "text/html"},
 "body" "<h2>hello world</h2>\n"}

Когда я go нажимаю на него в браузере, я получаю "502 плохой шлюз".

Где я чувствую себя потерянным, если я жестко кодирую html в мою функцию запроса дескриптора, чтобы она выглядела так:

(defn handle-event [event]
  (pprint event)
  {
   "statusCode"        200,
   "statusDescription" "200 OK"
   "isBase64Encoded"   false
   "headers"           {
                        "Content-Type" "text/html"}

   "body" "<h1>hello world</h1>\n"})

Затем я получаю «привет мир» в браузере.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...