module Network.AWS.Lambda.Types
(
Lambda
, JSONError
, Runtime (..)
, Mode (..)
, FunctionCodeLocation
, functionCodeLocation
, fclLocation
, fclRepositoryType
, FunctionConfiguration
, functionConfiguration
, fcCodeSize
, fcConfigurationId
, fcDescription
, fcFunctionARN
, fcFunctionName
, fcHandler
, fcLastModified
, fcMemorySize
, fcMode
, fcRole
, fcRuntime
, fcTimeout
, EventSourceConfiguration
, eventSourceConfiguration
, escBatchSize
, escEventSource
, escFunctionName
, escIsActive
, escLastModified
, escParameters
, escRole
, escStatus
, escUUID
) where
import Network.AWS.Prelude
import Network.AWS.Signing
import qualified GHC.Exts
data Lambda
instance AWSService Lambda where
type Sg Lambda = V4
type Er Lambda = JSONError
service = service'
where
service' :: Service Lambda
service' = Service
{ _svcAbbrev = "Lambda"
, _svcPrefix = "lambda"
, _svcVersion = "2014-11-11"
, _svcTargetPrefix = Nothing
, _svcJSONVersion = Nothing
, _svcHandle = handle
, _svcRetry = retry
}
handle :: Status
-> Maybe (LazyByteString -> ServiceError JSONError)
handle = jsonError statusSuccess service'
retry :: Retry Lambda
retry = Exponential
{ _retryBase = 0.05
, _retryGrowth = 2
, _retryAttempts = 5
, _retryCheck = check
}
check :: Status
-> JSONError
-> Bool
check (statusCode -> s) (awsErrorCode -> e)
| s == 500 = True
| s == 509 = True
| s == 503 = True
| otherwise = False
data Runtime
= Nodejs
deriving (Eq, Ord, Read, Show, Generic, Enum)
instance Hashable Runtime
instance FromText Runtime where
parser = takeLowerText >>= \case
"nodejs" -> pure Nodejs
e -> fail $
"Failure parsing Runtime from " ++ show e
instance ToText Runtime where
toText Nodejs = "nodejs"
instance ToByteString Runtime
instance ToHeader Runtime
instance ToQuery Runtime
instance FromJSON Runtime where
parseJSON = parseJSONText "Runtime"
instance ToJSON Runtime where
toJSON = toJSONText
data Mode
= Event
deriving (Eq, Ord, Read, Show, Generic, Enum)
instance Hashable Mode
instance FromText Mode where
parser = takeLowerText >>= \case
"event" -> pure Event
e -> fail $
"Failure parsing Mode from " ++ show e
instance ToText Mode where
toText Event = "event"
instance ToByteString Mode
instance ToHeader Mode
instance ToQuery Mode
instance FromJSON Mode where
parseJSON = parseJSONText "Mode"
instance ToJSON Mode where
toJSON = toJSONText
data FunctionCodeLocation = FunctionCodeLocation
{ _fclLocation :: Maybe Text
, _fclRepositoryType :: Maybe Text
} deriving (Eq, Ord, Read, Show)
functionCodeLocation :: FunctionCodeLocation
functionCodeLocation = FunctionCodeLocation
{ _fclRepositoryType = Nothing
, _fclLocation = Nothing
}
fclLocation :: Lens' FunctionCodeLocation (Maybe Text)
fclLocation = lens _fclLocation (\s a -> s { _fclLocation = a })
fclRepositoryType :: Lens' FunctionCodeLocation (Maybe Text)
fclRepositoryType =
lens _fclRepositoryType (\s a -> s { _fclRepositoryType = a })
instance FromJSON FunctionCodeLocation where
parseJSON = withObject "FunctionCodeLocation" $ \o -> FunctionCodeLocation
<$> o .:? "Location"
<*> o .:? "RepositoryType"
instance ToJSON FunctionCodeLocation where
toJSON FunctionCodeLocation{..} = object
[ "RepositoryType" .= _fclRepositoryType
, "Location" .= _fclLocation
]
data FunctionConfiguration = FunctionConfiguration
{ _fcCodeSize :: Maybe Integer
, _fcConfigurationId :: Maybe Text
, _fcDescription :: Maybe Text
, _fcFunctionARN :: Maybe Text
, _fcFunctionName :: Maybe Text
, _fcHandler :: Maybe Text
, _fcLastModified :: Maybe POSIX
, _fcMemorySize :: Maybe Nat
, _fcMode :: Maybe Mode
, _fcRole :: Maybe Text
, _fcRuntime :: Maybe Runtime
, _fcTimeout :: Maybe Nat
} deriving (Eq, Read, Show)
functionConfiguration :: FunctionConfiguration
functionConfiguration = FunctionConfiguration
{ _fcFunctionName = Nothing
, _fcFunctionARN = Nothing
, _fcConfigurationId = Nothing
, _fcRuntime = Nothing
, _fcRole = Nothing
, _fcHandler = Nothing
, _fcMode = Nothing
, _fcCodeSize = Nothing
, _fcDescription = Nothing
, _fcTimeout = Nothing
, _fcMemorySize = Nothing
, _fcLastModified = Nothing
}
fcCodeSize :: Lens' FunctionConfiguration (Maybe Integer)
fcCodeSize = lens _fcCodeSize (\s a -> s { _fcCodeSize = a })
fcConfigurationId :: Lens' FunctionConfiguration (Maybe Text)
fcConfigurationId =
lens _fcConfigurationId (\s a -> s { _fcConfigurationId = a })
fcDescription :: Lens' FunctionConfiguration (Maybe Text)
fcDescription = lens _fcDescription (\s a -> s { _fcDescription = a })
fcFunctionARN :: Lens' FunctionConfiguration (Maybe Text)
fcFunctionARN = lens _fcFunctionARN (\s a -> s { _fcFunctionARN = a })
fcFunctionName :: Lens' FunctionConfiguration (Maybe Text)
fcFunctionName = lens _fcFunctionName (\s a -> s { _fcFunctionName = a })
fcHandler :: Lens' FunctionConfiguration (Maybe Text)
fcHandler = lens _fcHandler (\s a -> s { _fcHandler = a })
fcLastModified :: Lens' FunctionConfiguration (Maybe UTCTime)
fcLastModified = lens _fcLastModified (\s a -> s { _fcLastModified = a }) . mapping _Time
fcMemorySize :: Lens' FunctionConfiguration (Maybe Natural)
fcMemorySize = lens _fcMemorySize (\s a -> s { _fcMemorySize = a }) . mapping _Nat
fcMode :: Lens' FunctionConfiguration (Maybe Mode)
fcMode = lens _fcMode (\s a -> s { _fcMode = a })
fcRole :: Lens' FunctionConfiguration (Maybe Text)
fcRole = lens _fcRole (\s a -> s { _fcRole = a })
fcRuntime :: Lens' FunctionConfiguration (Maybe Runtime)
fcRuntime = lens _fcRuntime (\s a -> s { _fcRuntime = a })
fcTimeout :: Lens' FunctionConfiguration (Maybe Natural)
fcTimeout = lens _fcTimeout (\s a -> s { _fcTimeout = a }) . mapping _Nat
instance FromJSON FunctionConfiguration where
parseJSON = withObject "FunctionConfiguration" $ \o -> FunctionConfiguration
<$> o .:? "CodeSize"
<*> o .:? "ConfigurationId"
<*> o .:? "Description"
<*> o .:? "FunctionARN"
<*> o .:? "FunctionName"
<*> o .:? "Handler"
<*> o .:? "LastModified"
<*> o .:? "MemorySize"
<*> o .:? "Mode"
<*> o .:? "Role"
<*> o .:? "Runtime"
<*> o .:? "Timeout"
instance ToJSON FunctionConfiguration where
toJSON FunctionConfiguration{..} = object
[ "FunctionName" .= _fcFunctionName
, "FunctionARN" .= _fcFunctionARN
, "ConfigurationId" .= _fcConfigurationId
, "Runtime" .= _fcRuntime
, "Role" .= _fcRole
, "Handler" .= _fcHandler
, "Mode" .= _fcMode
, "CodeSize" .= _fcCodeSize
, "Description" .= _fcDescription
, "Timeout" .= _fcTimeout
, "MemorySize" .= _fcMemorySize
, "LastModified" .= _fcLastModified
]
data EventSourceConfiguration = EventSourceConfiguration
{ _escBatchSize :: Maybe Int
, _escEventSource :: Maybe Text
, _escFunctionName :: Maybe Text
, _escIsActive :: Maybe Bool
, _escLastModified :: Maybe POSIX
, _escParameters :: Map Text Text
, _escRole :: Maybe Text
, _escStatus :: Maybe Text
, _escUUID :: Maybe Text
} deriving (Eq, Read, Show)
eventSourceConfiguration :: EventSourceConfiguration
eventSourceConfiguration = EventSourceConfiguration
{ _escUUID = Nothing
, _escBatchSize = Nothing
, _escEventSource = Nothing
, _escFunctionName = Nothing
, _escParameters = mempty
, _escRole = Nothing
, _escLastModified = Nothing
, _escIsActive = Nothing
, _escStatus = Nothing
}
escBatchSize :: Lens' EventSourceConfiguration (Maybe Int)
escBatchSize = lens _escBatchSize (\s a -> s { _escBatchSize = a })
escEventSource :: Lens' EventSourceConfiguration (Maybe Text)
escEventSource = lens _escEventSource (\s a -> s { _escEventSource = a })
escFunctionName :: Lens' EventSourceConfiguration (Maybe Text)
escFunctionName = lens _escFunctionName (\s a -> s { _escFunctionName = a })
escIsActive :: Lens' EventSourceConfiguration (Maybe Bool)
escIsActive = lens _escIsActive (\s a -> s { _escIsActive = a })
escLastModified :: Lens' EventSourceConfiguration (Maybe UTCTime)
escLastModified = lens _escLastModified (\s a -> s { _escLastModified = a }) . mapping _Time
escParameters :: Lens' EventSourceConfiguration (HashMap Text Text)
escParameters = lens _escParameters (\s a -> s { _escParameters = a }) . _Map
escRole :: Lens' EventSourceConfiguration (Maybe Text)
escRole = lens _escRole (\s a -> s { _escRole = a })
escStatus :: Lens' EventSourceConfiguration (Maybe Text)
escStatus = lens _escStatus (\s a -> s { _escStatus = a })
escUUID :: Lens' EventSourceConfiguration (Maybe Text)
escUUID = lens _escUUID (\s a -> s { _escUUID = a })
instance FromJSON EventSourceConfiguration where
parseJSON = withObject "EventSourceConfiguration" $ \o -> EventSourceConfiguration
<$> o .:? "BatchSize"
<*> o .:? "EventSource"
<*> o .:? "FunctionName"
<*> o .:? "IsActive"
<*> o .:? "LastModified"
<*> o .:? "Parameters" .!= mempty
<*> o .:? "Role"
<*> o .:? "Status"
<*> o .:? "UUID"
instance ToJSON EventSourceConfiguration where
toJSON EventSourceConfiguration{..} = object
[ "UUID" .= _escUUID
, "BatchSize" .= _escBatchSize
, "EventSource" .= _escEventSource
, "FunctionName" .= _escFunctionName
, "Parameters" .= _escParameters
, "Role" .= _escRole
, "LastModified" .= _escLastModified
, "IsActive" .= _escIsActive
, "Status" .= _escStatus
]