Copyright | (c) Nike Inc. 2019 |
---|---|
License | BSD3 |
Maintainer | nathan.fairhurst@nike.com, fernando.freire@nike.com |
Stability | stable |
Safe Haskell | None |
Language | Haskell2010 |
This module exposes types used to model incoming proxy requests from AWS API Gateway. These types are a light pass over the incoming JSON representation.
Synopsis
- data ProxyRequest a = ProxyRequest {
- path :: Text
- headers :: HashMap (CI Text) Text
- multiValueHeaders :: HashMap (CI Text) [Text]
- pathParameters :: HashMap Text Text
- stageVariables :: HashMap Text Text
- requestContext :: RequestContext a
- resource :: Text
- httpMethod :: Text
- queryStringParameters :: HashMap Text Text
- multiValueQueryStringParameters :: HashMap Text [Text]
- body :: ByteString
- data RequestContext a = RequestContext {
- path :: Text
- accountId :: Text
- authorizer :: Maybe a
- resourceId :: Text
- stage :: Text
- domainPrefix :: Maybe Text
- requestId :: Text
- identity :: Identity
- domainName :: Maybe Text
- resourcePath :: Text
- httpMethod :: Text
- extendedRequestId :: Maybe Text
- apiId :: Text
- data Identity = Identity {
- cognitoIdentityPoolId :: Maybe Text
- accountId :: Maybe Text
- cognitoIdentityId :: Maybe Text
- caller :: Maybe Text
- apiKey :: Maybe Text
- sourceIp :: Text
- accessKey :: Maybe Text
- cognitoAuthenticationType :: Maybe Text
- cognitoAuthenticationProvider :: Maybe Text
- userArn :: Maybe Text
- apiKeyId :: Maybe Text
- userAgent :: Maybe Text
- user :: Maybe Text
- type NoAuthorizer = Value
- type StrictlyNoAuthorizer = Void
Documentation
data ProxyRequest a Source #
This type is for representing events that come from API Gateway via the Lambda Proxy integration (forwarding HTTP data directly, rather than a custom integration). It will automatically decode the event that comes in.
The ProxyRequest
notably has one parameter for the type of information
returned by the API Gateway's custom authorizer (if applicable). This type
must also implement FromJSON so that it can be decoded. If you do not
expect this data to be populated we recommended using the NoAuthorizer
type exported from this module (which is just an alias for Value
). If
there _must not_ be authorizer populated (this is unlikely) then use the
StrictlyNoAuthorizer
type.
{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE DuplicateRecordFields #-} module Main where import AWS.Lambda.Runtime (pureRuntime) import AWS.Lambda.Events.ApiGateway.ProxyRequest (ProxyRequest(..), NoAuthorizer) import AWS.Lambda.Events.ApiGateway.ProxyResponse (ProxyResponse(..), textPlain, forbidden403, ok200) myHandler :: ProxyRequest NoAuthorizer -> ProxyResponse myHandler ProxyRequest { httpMethod = "GET", path = "/say_hello" } = ProxyResponse { status = ok200 , body = textPlain "Hello" , headers = mempty , multiValueHeaders = mempty } myHandler _ = ProxyResponse { status = forbidden403 , body = textPlain "Forbidden" , headers = mempty , multiValueHeaders = mempty } main :: IO () main = pureRuntime myHandler
ProxyRequest | |
|
Instances
data RequestContext a Source #
RequestContext | |
|
Instances
FromJSON a => FromJSON (RequestContext a) Source # | |
Defined in AWS.Lambda.Events.ApiGateway.ProxyRequest parseJSON :: Value -> Parser (RequestContext a) # parseJSONList :: Value -> Parser [RequestContext a] # |
Identity | |
|
Instances
type NoAuthorizer = Value Source #
For ignoring API Gateway custom authorizer values
type StrictlyNoAuthorizer = Void Source #
For ensuring that there were no API Gateway custom authorizer values (this
is not likely to be useful, you probably want NoAuthorizer
)