You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/02-adding-a-handler.md
+3-2Lines changed: 3 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,7 @@ modules:
21
21
```haskell
22
22
{-# LANGUAGE DeriveGeneric #-}
23
23
{-# LANGUAGE DeriveAnyClass #-}
24
+
24
25
moduleLibwhere
25
26
```
26
27
@@ -46,7 +47,7 @@ Now, let's write the handler. It **must** be a function that is called `handler`
46
47
The arguments to this function will always go like this:
47
48
48
49
*The first argument to this handler will always be the input type we expect (note that it has to implement `FromJSON`).
49
-
*The second argument is the `Aws.Lambda` `Context` type, which has some information regarding our Lambda execution.
50
+
*The second argument is the `Aws.Lambda` `Context` type, which has some information regarding our Lambda execution.The `Context` type also takes a `context` parameter, which we can use if we want to have some state that is shared between Lambda calls.For this example, we don't want to have such state, so we'll just use `()`.
50
51
51
52
The output will always be an `IO (Either errorType resultType)` where
52
53
@@ -59,7 +60,7 @@ For example, here we will check if the age of a `Person` is positive, and will r
Copy file name to clipboardExpand all lines: doc/03-configuring-the-dispatcher.md
+18-5Lines changed: 18 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,34 @@ The dispatcher is a special main function that checks which handler it has to ru
8
8
and runs it
9
9
10
10
To make the package generate a dispatcher for you, you have to configure it in
11
-
your `app/Main.hs` file.
11
+
your `app/Main.hs` file to use the `generateLambdaDispatcher` function from `Aws.Lambda`.
12
12
13
-
First, activate `TemplateHaskell` for enabling the metaprogramming features of Haskell.
13
+
The `generateLambdaDispatcher` function has two options: `StandaloneLambda` and `UseWithAPIGateway`.
14
+
15
+
Use `UseWithAPIGateway` when you'll be exposing your lambda through API Gateway. For more information check the [Use with API Gateway](./04-usage-with-api-gateway.md) page.
16
+
17
+
Use `StandaloneLambda` when you want to use your lambda as usual. This is what we're going to use for our person age validator function.
18
+
19
+
To continue the person age validator lambda, activate `TemplateHaskell` for enabling the metaprogramming features of Haskell.
14
20
Then, import the `Aws.Lambda` module:
15
21
16
22
```haskell
17
-
{-# LANGUAGE TemplateHaskell #-}
23
+
{-# LANGUAGE TemplateHaskell #-}
24
+
{-# LANGUAGE ScopedTypeVariables #-}
25
+
18
26
moduleMainwhere
19
27
importAws.Lambda
20
28
```
21
29
22
-
After this, add a line with the following statement:
30
+
After this, add the following lines:
23
31
24
32
```haskell
25
-
generateLambdaDispatcher
33
+
-- Use this action if you want to have context that is shared between lambda calls.
34
+
-- It is called once per every cold start. We do not wish to have a shared context for our lambda, so we simply use Unit.
Again, you can use this typein your project, and use only the fields you need.
53
-
Note that `HeaderName` comes from [`Network.HTTP.Simple`](https://hackage.haskell.org/package/http-conduit-2.3.7.1/docs/Network-HTTP-Simple.html#t:Header).
54
-
55
-
Notice some fields need implementation ofToJSON.See the example with headers below.
You can use the `ApiGatewayRequest` wrapper to access additional request information that API Gateway provides, such as path, query string parameters, authentication info and much more. You can find more information about that under the `Input format of a Lambda function for proxy integration` section [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html).
71
23
72
-
-- Input
73
-
dataEvent=Event
74
-
{resource::String
75
-
, body::String
76
-
}deriving (Generic, FromJSON)
24
+
You can use the `ApiGatewayResponse` wrapper in order to return a custom status code or attach custom headers to the response.
77
25
78
-
-- Output
79
-
dataResponse=Response
80
-
{statusCode::Int
81
-
, body::String
82
-
}deriving (Generic, ToJSON)
26
+
Also note the `defaultDispatcherOptions`. They look like this:
For production environments, you'd likely want to set `propagateImpureExceptions` to `False` in order to prevent your exception messages from being seen.
0 commit comments