This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
bastions-on-demand/service/api/lambda/trigger-bastion-destruction/src/trigger_bastion_destruction/handler.cljs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (23 sloc)
853 Bytes
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
(ns trigger-bastion-destruction.handler | |
(:require [clojure.string :as cs] | |
[cljs.nodejs :as node])) | |
(node/enable-util-print!) | |
(def AWS | |
(node/require "aws-sdk")) | |
(def lambda | |
(new AWS.Lambda)) | |
(defn env | |
[k] | |
(aget js/process.env k)) | |
(def destroy-bastion-function-name (env "DESTROY_BASTION_FUNCTION_NAME")) | |
(defn ^:export handle-request | |
[event _ callback] | |
(let [event (js->clj event :keywordize-keys true) | |
user (last (cs/split (get-in event [:requestContext :identity :userArn]) #"/")) | |
payload (.stringify js/JSON (clj->js {:user user}))] | |
(.invoke lambda | |
(clj->js {:FunctionName destroy-bastion-function-name | |
:InvocationType "Event" | |
:Payload payload}) | |
(fn [_ _] | |
(callback nil (clj->js {:statusCode 200})))))) |