Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start using amazonka for AWS interactions
- Loading branch information
Showing
9 changed files
with
107 additions
and
48 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module System.Build where | ||
|
||
import Data.ByteString (hGet, hPut, null) | ||
import Data.Functor (void) | ||
import Prelude hiding (null) | ||
import System.Directory | ||
import System.Exit | ||
import System.IO | ||
import System.Process | ||
|
||
buildDocker :: IO () | ||
buildDocker = callProcess "docker" ["build", "-t", "ghc-centos","ghc-centos" ] | ||
|
||
copy :: Handle -> Handle -> IO () | ||
copy hIn hOut = do | ||
bs <- hGet hIn 4096 | ||
if not (null bs) | ||
then hPut hOut bs >> copy hIn hOut | ||
else return () | ||
|
||
buildExecutable :: FilePath -> String -> IO FilePath | ||
buildExecutable srcDir targetName = do | ||
absSrcDir <- canonicalizePath srcDir | ||
removeFile ".cidfile" | ||
(_,_,_,hdl) <- createProcess $ proc "docker" ["run", "--cidfile=.cidfile", "-v", absSrcDir ++ ":/build", "-w", "/build" , "ghc-centos","stack", "build","--allow-different-user", targetName ] | ||
exitCode <- waitForProcess hdl | ||
case exitCode of | ||
ExitSuccess -> do | ||
cid <- readFile ".cidfile" | ||
(_, Just hout, _, phdl) <- createProcess $ (proc "docker" ["run", "--volumes-from=" ++ cid, "busybox","dd", "if=/build/.stack-work/install/x86_64-linux/lts-5.17/7.10.3/bin/"++ targetName ]) { std_out = CreatePipe } | ||
withBinaryFile "lambda" WriteMode $ \ hDst -> copy hout hDst | ||
void $ waitForProcess phdl | ||
return "lambda" | ||
ExitFailure code -> fail $ "failed to build correctly " ++ targetName ++ " in directory " ++ srcDir ++ ": " ++ show code | ||
|
||
packLambda :: FilePath -> IO () | ||
packLambda exe = callProcess "zip" [ "lambda.zip", "run.js", exe ] |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- Initial aws-lambda-haskell.cabal generated by cabal init. For further | ||
-- documentation, see http://haskell.org/cabal/users-guide/ | ||
|
||
name: main | ||
version: 0.1.0.0 | ||
-- synopsis: | ||
-- description: | ||
-- license: | ||
license-file: LICENSE | ||
author: Arnaud Bailly | ||
maintainer: arnaud.oqube@gmail.com | ||
-- copyright: | ||
-- category: | ||
build-type: Simple | ||
extra-source-files: README.md, README.md~ | ||
cabal-version: >=1.10 | ||
|
||
executable main | ||
main-is: main.hs | ||
-- other-modules: | ||
-- other-extensions: | ||
build-depends: base >=4.8 && <4.9 | ||
-- hs-source-dirs: | ||
default-language: Haskell2010 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Main where | ||
|
||
import System.IO | ||
|
||
main :: IO () | ||
main = do | ||
ln <- getLine | ||
putStrLn $ "Got: " ++ ln | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resolver: lts-5.17 | ||
packages: | ||
- '.' |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
module Main where | ||
|
||
import AWS.ApiGateway | ||
import Control.Lens | ||
import Control.Monad.Trans.AWS | ||
import Data.Text (pack) | ||
import Prelude hiding (null) | ||
import System.Build | ||
import System.Environment | ||
import System.IO | ||
|
||
main :: IO () | ||
main = do | ||
input <- getLine | ||
putStrLn $ "got " ++ input | ||
[ apiEndpoint, sourceDirectory, targetName ] <- getArgs | ||
-- build docker container | ||
buildDocker | ||
-- build executable with docker | ||
exe <- buildExecutable sourceDirectory targetName | ||
-- pack executable with js shim in .zip file | ||
_ <- packLambda exe | ||
lgr <- newLogger Trace stdout | ||
env <- newEnv Ireland Discover <&> envLogger .~ lgr | ||
createApiEndpoint env apiEndpoint >>= print | ||
|
||
where | ||
|
||
createApiEndpoint env api = runResourceT (runAWST env $ createApi $ pack api) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
resolver: ghc-7.10.3 | ||
resolver: lts-5.17 | ||
packages: | ||
- '.' |