{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SES.Types.LambdaAction
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SES.Types.LambdaAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SES.Types.InvocationType

-- | When included in a receipt rule, this action calls an AWS Lambda
-- function and, optionally, publishes a notification to Amazon Simple
-- Notification Service (Amazon SNS).
--
-- To enable Amazon SES to call your AWS Lambda function or to publish to
-- an Amazon SNS topic of another account, Amazon SES must have permission
-- to access those resources. For information about giving permissions, see
-- the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-permissions.html Amazon SES Developer Guide>.
--
-- For information about using AWS Lambda actions in receipt rules, see the
-- <https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email-action-lambda.html Amazon SES Developer Guide>.
--
-- /See:/ 'newLambdaAction' smart constructor.
data LambdaAction = LambdaAction'
  { -- | The invocation type of the AWS Lambda function. An invocation type of
    -- @RequestResponse@ means that the execution of the function will
    -- immediately result in a response, and a value of @Event@ means that the
    -- function will be invoked asynchronously. The default value is @Event@.
    -- For information about AWS Lambda invocation types, see the
    -- <https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html AWS Lambda Developer Guide>.
    --
    -- There is a 30-second timeout on @RequestResponse@ invocations. You
    -- should use @Event@ invocation in most cases. Use @RequestResponse@ only
    -- when you want to make a mail flow decision, such as whether to stop the
    -- receipt rule or the receipt rule set.
    LambdaAction -> Maybe InvocationType
invocationType :: Prelude.Maybe InvocationType,
    -- | The Amazon Resource Name (ARN) of the Amazon SNS topic to notify when
    -- the Lambda action is taken. An example of an Amazon SNS topic ARN is
    -- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
    -- Amazon SNS topics, see the
    -- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
    LambdaAction -> Maybe Text
topicArn :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the AWS Lambda function. An example of
    -- an AWS Lambda function ARN is
    -- @arn:aws:lambda:us-west-2:account-id:function:MyFunction@. For more
    -- information about AWS Lambda, see the
    -- <https://docs.aws.amazon.com/lambda/latest/dg/welcome.html AWS Lambda Developer Guide>.
    LambdaAction -> Text
functionArn :: Prelude.Text
  }
  deriving (LambdaAction -> LambdaAction -> Bool
(LambdaAction -> LambdaAction -> Bool)
-> (LambdaAction -> LambdaAction -> Bool) -> Eq LambdaAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaAction -> LambdaAction -> Bool
$c/= :: LambdaAction -> LambdaAction -> Bool
== :: LambdaAction -> LambdaAction -> Bool
$c== :: LambdaAction -> LambdaAction -> Bool
Prelude.Eq, ReadPrec [LambdaAction]
ReadPrec LambdaAction
Int -> ReadS LambdaAction
ReadS [LambdaAction]
(Int -> ReadS LambdaAction)
-> ReadS [LambdaAction]
-> ReadPrec LambdaAction
-> ReadPrec [LambdaAction]
-> Read LambdaAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaAction]
$creadListPrec :: ReadPrec [LambdaAction]
readPrec :: ReadPrec LambdaAction
$creadPrec :: ReadPrec LambdaAction
readList :: ReadS [LambdaAction]
$creadList :: ReadS [LambdaAction]
readsPrec :: Int -> ReadS LambdaAction
$creadsPrec :: Int -> ReadS LambdaAction
Prelude.Read, Int -> LambdaAction -> ShowS
[LambdaAction] -> ShowS
LambdaAction -> String
(Int -> LambdaAction -> ShowS)
-> (LambdaAction -> String)
-> ([LambdaAction] -> ShowS)
-> Show LambdaAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaAction] -> ShowS
$cshowList :: [LambdaAction] -> ShowS
show :: LambdaAction -> String
$cshow :: LambdaAction -> String
showsPrec :: Int -> LambdaAction -> ShowS
$cshowsPrec :: Int -> LambdaAction -> ShowS
Prelude.Show, (forall x. LambdaAction -> Rep LambdaAction x)
-> (forall x. Rep LambdaAction x -> LambdaAction)
-> Generic LambdaAction
forall x. Rep LambdaAction x -> LambdaAction
forall x. LambdaAction -> Rep LambdaAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LambdaAction x -> LambdaAction
$cfrom :: forall x. LambdaAction -> Rep LambdaAction x
Prelude.Generic)

-- |
-- Create a value of 'LambdaAction' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'invocationType', 'lambdaAction_invocationType' - The invocation type of the AWS Lambda function. An invocation type of
-- @RequestResponse@ means that the execution of the function will
-- immediately result in a response, and a value of @Event@ means that the
-- function will be invoked asynchronously. The default value is @Event@.
-- For information about AWS Lambda invocation types, see the
-- <https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html AWS Lambda Developer Guide>.
--
-- There is a 30-second timeout on @RequestResponse@ invocations. You
-- should use @Event@ invocation in most cases. Use @RequestResponse@ only
-- when you want to make a mail flow decision, such as whether to stop the
-- receipt rule or the receipt rule set.
--
-- 'topicArn', 'lambdaAction_topicArn' - The Amazon Resource Name (ARN) of the Amazon SNS topic to notify when
-- the Lambda action is taken. An example of an Amazon SNS topic ARN is
-- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
-- Amazon SNS topics, see the
-- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
--
-- 'functionArn', 'lambdaAction_functionArn' - The Amazon Resource Name (ARN) of the AWS Lambda function. An example of
-- an AWS Lambda function ARN is
-- @arn:aws:lambda:us-west-2:account-id:function:MyFunction@. For more
-- information about AWS Lambda, see the
-- <https://docs.aws.amazon.com/lambda/latest/dg/welcome.html AWS Lambda Developer Guide>.
newLambdaAction ::
  -- | 'functionArn'
  Prelude.Text ->
  LambdaAction
newLambdaAction :: Text -> LambdaAction
newLambdaAction Text
pFunctionArn_ =
  LambdaAction' :: Maybe InvocationType -> Maybe Text -> Text -> LambdaAction
LambdaAction'
    { $sel:invocationType:LambdaAction' :: Maybe InvocationType
invocationType = Maybe InvocationType
forall a. Maybe a
Prelude.Nothing,
      $sel:topicArn:LambdaAction' :: Maybe Text
topicArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionArn:LambdaAction' :: Text
functionArn = Text
pFunctionArn_
    }

-- | The invocation type of the AWS Lambda function. An invocation type of
-- @RequestResponse@ means that the execution of the function will
-- immediately result in a response, and a value of @Event@ means that the
-- function will be invoked asynchronously. The default value is @Event@.
-- For information about AWS Lambda invocation types, see the
-- <https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html AWS Lambda Developer Guide>.
--
-- There is a 30-second timeout on @RequestResponse@ invocations. You
-- should use @Event@ invocation in most cases. Use @RequestResponse@ only
-- when you want to make a mail flow decision, such as whether to stop the
-- receipt rule or the receipt rule set.
lambdaAction_invocationType :: Lens.Lens' LambdaAction (Prelude.Maybe InvocationType)
lambdaAction_invocationType :: (Maybe InvocationType -> f (Maybe InvocationType))
-> LambdaAction -> f LambdaAction
lambdaAction_invocationType = (LambdaAction -> Maybe InvocationType)
-> (LambdaAction -> Maybe InvocationType -> LambdaAction)
-> Lens
     LambdaAction
     LambdaAction
     (Maybe InvocationType)
     (Maybe InvocationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaAction' {Maybe InvocationType
invocationType :: Maybe InvocationType
$sel:invocationType:LambdaAction' :: LambdaAction -> Maybe InvocationType
invocationType} -> Maybe InvocationType
invocationType) (\s :: LambdaAction
s@LambdaAction' {} Maybe InvocationType
a -> LambdaAction
s {$sel:invocationType:LambdaAction' :: Maybe InvocationType
invocationType = Maybe InvocationType
a} :: LambdaAction)

-- | The Amazon Resource Name (ARN) of the Amazon SNS topic to notify when
-- the Lambda action is taken. An example of an Amazon SNS topic ARN is
-- @arn:aws:sns:us-west-2:123456789012:MyTopic@. For more information about
-- Amazon SNS topics, see the
-- <https://docs.aws.amazon.com/sns/latest/dg/CreateTopic.html Amazon SNS Developer Guide>.
lambdaAction_topicArn :: Lens.Lens' LambdaAction (Prelude.Maybe Prelude.Text)
lambdaAction_topicArn :: (Maybe Text -> f (Maybe Text)) -> LambdaAction -> f LambdaAction
lambdaAction_topicArn = (LambdaAction -> Maybe Text)
-> (LambdaAction -> Maybe Text -> LambdaAction)
-> Lens LambdaAction LambdaAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaAction' {Maybe Text
topicArn :: Maybe Text
$sel:topicArn:LambdaAction' :: LambdaAction -> Maybe Text
topicArn} -> Maybe Text
topicArn) (\s :: LambdaAction
s@LambdaAction' {} Maybe Text
a -> LambdaAction
s {$sel:topicArn:LambdaAction' :: Maybe Text
topicArn = Maybe Text
a} :: LambdaAction)

-- | The Amazon Resource Name (ARN) of the AWS Lambda function. An example of
-- an AWS Lambda function ARN is
-- @arn:aws:lambda:us-west-2:account-id:function:MyFunction@. For more
-- information about AWS Lambda, see the
-- <https://docs.aws.amazon.com/lambda/latest/dg/welcome.html AWS Lambda Developer Guide>.
lambdaAction_functionArn :: Lens.Lens' LambdaAction Prelude.Text
lambdaAction_functionArn :: (Text -> f Text) -> LambdaAction -> f LambdaAction
lambdaAction_functionArn = (LambdaAction -> Text)
-> (LambdaAction -> Text -> LambdaAction)
-> Lens LambdaAction LambdaAction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaAction' {Text
functionArn :: Text
$sel:functionArn:LambdaAction' :: LambdaAction -> Text
functionArn} -> Text
functionArn) (\s :: LambdaAction
s@LambdaAction' {} Text
a -> LambdaAction
s {$sel:functionArn:LambdaAction' :: Text
functionArn = Text
a} :: LambdaAction)

instance Core.FromXML LambdaAction where
  parseXML :: [Node] -> Either String LambdaAction
parseXML [Node]
x =
    Maybe InvocationType -> Maybe Text -> Text -> LambdaAction
LambdaAction'
      (Maybe InvocationType -> Maybe Text -> Text -> LambdaAction)
-> Either String (Maybe InvocationType)
-> Either String (Maybe Text -> Text -> LambdaAction)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe InvocationType)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"InvocationType")
      Either String (Maybe Text -> Text -> LambdaAction)
-> Either String (Maybe Text)
-> Either String (Text -> LambdaAction)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"TopicArn")
      Either String (Text -> LambdaAction)
-> Either String Text -> Either String LambdaAction
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"FunctionArn")

instance Prelude.Hashable LambdaAction

instance Prelude.NFData LambdaAction

instance Core.ToQuery LambdaAction where
  toQuery :: LambdaAction -> QueryString
toQuery LambdaAction' {Maybe Text
Maybe InvocationType
Text
functionArn :: Text
topicArn :: Maybe Text
invocationType :: Maybe InvocationType
$sel:functionArn:LambdaAction' :: LambdaAction -> Text
$sel:topicArn:LambdaAction' :: LambdaAction -> Maybe Text
$sel:invocationType:LambdaAction' :: LambdaAction -> Maybe InvocationType
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"InvocationType" ByteString -> Maybe InvocationType -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe InvocationType
invocationType,
        ByteString
"TopicArn" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
topicArn,
        ByteString
"FunctionArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
functionArn
      ]