Created
May 18, 2019 07:59
-
-
Save andreabedini/0773a640e71182712ae0a67d112b2dcf to your computer and use it in GitHub Desktop.
Mocking the service-side of AWS Lambda runtime (useful to test you own runtime implementations)
This file contains hidden or 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
| module Main (main) where | |
| import Control.Concurrent (newChan, readChan, writeChan) | |
| import Control.Monad.IO.Class (liftIO) | |
| import Data.Text (Text) | |
| import Web.Scotty | |
| main :: IO () | |
| main = do | |
| ch <- newChan | |
| scotty 3000 $ do | |
| post "/2018-06-01/runtime/invocation/next" $ do | |
| payload <- body | |
| liftIO $ writeChan ch payload | |
| get "/2018-06-01/runtime/invocation/next" $ do | |
| addHeader "Lambda-Runtime-Aws-Request-Id" "8476a536-e9f4-11e8-9739-2dfe598c3fcd" | |
| addHeader "Lambda-Runtime-Deadline-Ms" "1542409706888" | |
| addHeader "Lambda-Runtime-Invoked-Function-Arn" "arn:aws:lambda:us-east-2:123456789012:function:custom-runtime" | |
| addHeader "Lambda-Runtime-Trace-Id" "Root=1-5bef4de7-ad49b0e87f6ef6c87fc2e700;Parent=9a9197af755a6419;Sampled=1" | |
| setHeader "Content-Type" "application/json" | |
| payload <- liftIO $ readChan ch | |
| raw payload | |
| post "/2018-06-01/runtime/invocation/:awsRequestId/response" $ do | |
| awsRequestId <- param "awsRequestId" :: ActionM Text | |
| liftIO $ print $ "Received response for " <> awsRequestId | |
| post "/2018-06-01/runtime/invocation/:awsRequestId/error" $ do | |
| awsRequestId <- param "awsRequestId" :: ActionM Text | |
| liftIO $ print $ "Received error for " <> awsRequestId | |
| post "/2018-06-01/runtime/init/error" $ do | |
| payload <- body | |
| liftIO $ print $ "Received initialization error for " <> payload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment