{-# 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.S3.Types.LambdaFunctionConfiguration
-- 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.S3.Types.LambdaFunctionConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.Event
import Amazonka.S3.Types.NotificationConfigurationFilter

-- | A container for specifying the configuration for Lambda notifications.
--
-- /See:/ 'newLambdaFunctionConfiguration' smart constructor.
data LambdaFunctionConfiguration = LambdaFunctionConfiguration'
  { LambdaFunctionConfiguration -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    LambdaFunctionConfiguration
-> Maybe NotificationConfigurationFilter
filter' :: Prelude.Maybe NotificationConfigurationFilter,
    -- | The Amazon Resource Name (ARN) of the Lambda function that Amazon S3
    -- invokes when the specified event type occurs.
    LambdaFunctionConfiguration -> Text
lambdaFunctionArn :: Prelude.Text,
    -- | The Amazon S3 bucket event for which to invoke the Lambda function. For
    -- more information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Supported Event Types>
    -- in the /Amazon S3 User Guide/.
    LambdaFunctionConfiguration -> [Event]
events :: [Event]
  }
  deriving (LambdaFunctionConfiguration -> LambdaFunctionConfiguration -> Bool
(LambdaFunctionConfiguration
 -> LambdaFunctionConfiguration -> Bool)
-> (LambdaFunctionConfiguration
    -> LambdaFunctionConfiguration -> Bool)
-> Eq LambdaFunctionConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaFunctionConfiguration -> LambdaFunctionConfiguration -> Bool
$c/= :: LambdaFunctionConfiguration -> LambdaFunctionConfiguration -> Bool
== :: LambdaFunctionConfiguration -> LambdaFunctionConfiguration -> Bool
$c== :: LambdaFunctionConfiguration -> LambdaFunctionConfiguration -> Bool
Prelude.Eq, ReadPrec [LambdaFunctionConfiguration]
ReadPrec LambdaFunctionConfiguration
Int -> ReadS LambdaFunctionConfiguration
ReadS [LambdaFunctionConfiguration]
(Int -> ReadS LambdaFunctionConfiguration)
-> ReadS [LambdaFunctionConfiguration]
-> ReadPrec LambdaFunctionConfiguration
-> ReadPrec [LambdaFunctionConfiguration]
-> Read LambdaFunctionConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaFunctionConfiguration]
$creadListPrec :: ReadPrec [LambdaFunctionConfiguration]
readPrec :: ReadPrec LambdaFunctionConfiguration
$creadPrec :: ReadPrec LambdaFunctionConfiguration
readList :: ReadS [LambdaFunctionConfiguration]
$creadList :: ReadS [LambdaFunctionConfiguration]
readsPrec :: Int -> ReadS LambdaFunctionConfiguration
$creadsPrec :: Int -> ReadS LambdaFunctionConfiguration
Prelude.Read, Int -> LambdaFunctionConfiguration -> ShowS
[LambdaFunctionConfiguration] -> ShowS
LambdaFunctionConfiguration -> String
(Int -> LambdaFunctionConfiguration -> ShowS)
-> (LambdaFunctionConfiguration -> String)
-> ([LambdaFunctionConfiguration] -> ShowS)
-> Show LambdaFunctionConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaFunctionConfiguration] -> ShowS
$cshowList :: [LambdaFunctionConfiguration] -> ShowS
show :: LambdaFunctionConfiguration -> String
$cshow :: LambdaFunctionConfiguration -> String
showsPrec :: Int -> LambdaFunctionConfiguration -> ShowS
$cshowsPrec :: Int -> LambdaFunctionConfiguration -> ShowS
Prelude.Show, (forall x.
 LambdaFunctionConfiguration -> Rep LambdaFunctionConfiguration x)
-> (forall x.
    Rep LambdaFunctionConfiguration x -> LambdaFunctionConfiguration)
-> Generic LambdaFunctionConfiguration
forall x.
Rep LambdaFunctionConfiguration x -> LambdaFunctionConfiguration
forall x.
LambdaFunctionConfiguration -> Rep LambdaFunctionConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep LambdaFunctionConfiguration x -> LambdaFunctionConfiguration
$cfrom :: forall x.
LambdaFunctionConfiguration -> Rep LambdaFunctionConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'LambdaFunctionConfiguration' 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:
--
-- 'id', 'lambdaFunctionConfiguration_id' - Undocumented member.
--
-- 'filter'', 'lambdaFunctionConfiguration_filter' - Undocumented member.
--
-- 'lambdaFunctionArn', 'lambdaFunctionConfiguration_lambdaFunctionArn' - The Amazon Resource Name (ARN) of the Lambda function that Amazon S3
-- invokes when the specified event type occurs.
--
-- 'events', 'lambdaFunctionConfiguration_events' - The Amazon S3 bucket event for which to invoke the Lambda function. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Supported Event Types>
-- in the /Amazon S3 User Guide/.
newLambdaFunctionConfiguration ::
  -- | 'lambdaFunctionArn'
  Prelude.Text ->
  LambdaFunctionConfiguration
newLambdaFunctionConfiguration :: Text -> LambdaFunctionConfiguration
newLambdaFunctionConfiguration Text
pLambdaFunctionArn_ =
  LambdaFunctionConfiguration' :: Maybe Text
-> Maybe NotificationConfigurationFilter
-> Text
-> [Event]
-> LambdaFunctionConfiguration
LambdaFunctionConfiguration'
    { $sel:id:LambdaFunctionConfiguration' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filter':LambdaFunctionConfiguration' :: Maybe NotificationConfigurationFilter
filter' = Maybe NotificationConfigurationFilter
forall a. Maybe a
Prelude.Nothing,
      $sel:lambdaFunctionArn:LambdaFunctionConfiguration' :: Text
lambdaFunctionArn = Text
pLambdaFunctionArn_,
      $sel:events:LambdaFunctionConfiguration' :: [Event]
events = [Event]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Undocumented member.
lambdaFunctionConfiguration_id :: Lens.Lens' LambdaFunctionConfiguration (Prelude.Maybe Prelude.Text)
lambdaFunctionConfiguration_id :: (Maybe Text -> f (Maybe Text))
-> LambdaFunctionConfiguration -> f LambdaFunctionConfiguration
lambdaFunctionConfiguration_id = (LambdaFunctionConfiguration -> Maybe Text)
-> (LambdaFunctionConfiguration
    -> Maybe Text -> LambdaFunctionConfiguration)
-> Lens
     LambdaFunctionConfiguration
     LambdaFunctionConfiguration
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionConfiguration' {Maybe Text
id :: Maybe Text
$sel:id:LambdaFunctionConfiguration' :: LambdaFunctionConfiguration -> Maybe Text
id} -> Maybe Text
id) (\s :: LambdaFunctionConfiguration
s@LambdaFunctionConfiguration' {} Maybe Text
a -> LambdaFunctionConfiguration
s {$sel:id:LambdaFunctionConfiguration' :: Maybe Text
id = Maybe Text
a} :: LambdaFunctionConfiguration)

-- | Undocumented member.
lambdaFunctionConfiguration_filter :: Lens.Lens' LambdaFunctionConfiguration (Prelude.Maybe NotificationConfigurationFilter)
lambdaFunctionConfiguration_filter :: (Maybe NotificationConfigurationFilter
 -> f (Maybe NotificationConfigurationFilter))
-> LambdaFunctionConfiguration -> f LambdaFunctionConfiguration
lambdaFunctionConfiguration_filter = (LambdaFunctionConfiguration
 -> Maybe NotificationConfigurationFilter)
-> (LambdaFunctionConfiguration
    -> Maybe NotificationConfigurationFilter
    -> LambdaFunctionConfiguration)
-> Lens
     LambdaFunctionConfiguration
     LambdaFunctionConfiguration
     (Maybe NotificationConfigurationFilter)
     (Maybe NotificationConfigurationFilter)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionConfiguration' {Maybe NotificationConfigurationFilter
filter' :: Maybe NotificationConfigurationFilter
$sel:filter':LambdaFunctionConfiguration' :: LambdaFunctionConfiguration
-> Maybe NotificationConfigurationFilter
filter'} -> Maybe NotificationConfigurationFilter
filter') (\s :: LambdaFunctionConfiguration
s@LambdaFunctionConfiguration' {} Maybe NotificationConfigurationFilter
a -> LambdaFunctionConfiguration
s {$sel:filter':LambdaFunctionConfiguration' :: Maybe NotificationConfigurationFilter
filter' = Maybe NotificationConfigurationFilter
a} :: LambdaFunctionConfiguration)

-- | The Amazon Resource Name (ARN) of the Lambda function that Amazon S3
-- invokes when the specified event type occurs.
lambdaFunctionConfiguration_lambdaFunctionArn :: Lens.Lens' LambdaFunctionConfiguration Prelude.Text
lambdaFunctionConfiguration_lambdaFunctionArn :: (Text -> f Text)
-> LambdaFunctionConfiguration -> f LambdaFunctionConfiguration
lambdaFunctionConfiguration_lambdaFunctionArn = (LambdaFunctionConfiguration -> Text)
-> (LambdaFunctionConfiguration
    -> Text -> LambdaFunctionConfiguration)
-> Lens
     LambdaFunctionConfiguration LambdaFunctionConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionConfiguration' {Text
lambdaFunctionArn :: Text
$sel:lambdaFunctionArn:LambdaFunctionConfiguration' :: LambdaFunctionConfiguration -> Text
lambdaFunctionArn} -> Text
lambdaFunctionArn) (\s :: LambdaFunctionConfiguration
s@LambdaFunctionConfiguration' {} Text
a -> LambdaFunctionConfiguration
s {$sel:lambdaFunctionArn:LambdaFunctionConfiguration' :: Text
lambdaFunctionArn = Text
a} :: LambdaFunctionConfiguration)

-- | The Amazon S3 bucket event for which to invoke the Lambda function. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html Supported Event Types>
-- in the /Amazon S3 User Guide/.
lambdaFunctionConfiguration_events :: Lens.Lens' LambdaFunctionConfiguration [Event]
lambdaFunctionConfiguration_events :: ([Event] -> f [Event])
-> LambdaFunctionConfiguration -> f LambdaFunctionConfiguration
lambdaFunctionConfiguration_events = (LambdaFunctionConfiguration -> [Event])
-> (LambdaFunctionConfiguration
    -> [Event] -> LambdaFunctionConfiguration)
-> Lens
     LambdaFunctionConfiguration
     LambdaFunctionConfiguration
     [Event]
     [Event]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionConfiguration' {[Event]
events :: [Event]
$sel:events:LambdaFunctionConfiguration' :: LambdaFunctionConfiguration -> [Event]
events} -> [Event]
events) (\s :: LambdaFunctionConfiguration
s@LambdaFunctionConfiguration' {} [Event]
a -> LambdaFunctionConfiguration
s {$sel:events:LambdaFunctionConfiguration' :: [Event]
events = [Event]
a} :: LambdaFunctionConfiguration) (([Event] -> f [Event])
 -> LambdaFunctionConfiguration -> f LambdaFunctionConfiguration)
-> (([Event] -> f [Event]) -> [Event] -> f [Event])
-> ([Event] -> f [Event])
-> LambdaFunctionConfiguration
-> f LambdaFunctionConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Event] -> f [Event]) -> [Event] -> f [Event]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML LambdaFunctionConfiguration where
  parseXML :: [Node] -> Either String LambdaFunctionConfiguration
parseXML [Node]
x =
    Maybe Text
-> Maybe NotificationConfigurationFilter
-> Text
-> [Event]
-> LambdaFunctionConfiguration
LambdaFunctionConfiguration'
      (Maybe Text
 -> Maybe NotificationConfigurationFilter
 -> Text
 -> [Event]
 -> LambdaFunctionConfiguration)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe NotificationConfigurationFilter
      -> Text -> [Event] -> LambdaFunctionConfiguration)
forall (f :: * -> *) a b. Functor 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
"Id")
      Either
  String
  (Maybe NotificationConfigurationFilter
   -> Text -> [Event] -> LambdaFunctionConfiguration)
-> Either String (Maybe NotificationConfigurationFilter)
-> Either String (Text -> [Event] -> LambdaFunctionConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text -> Either String (Maybe NotificationConfigurationFilter)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Filter")
      Either String (Text -> [Event] -> LambdaFunctionConfiguration)
-> Either String Text
-> Either String ([Event] -> LambdaFunctionConfiguration)
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
"CloudFunction")
      Either String ([Event] -> LambdaFunctionConfiguration)
-> Either String [Event]
-> Either String LambdaFunctionConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Text -> [Node] -> Either String [Event]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Event" [Node]
x)

instance Prelude.Hashable LambdaFunctionConfiguration

instance Prelude.NFData LambdaFunctionConfiguration

instance Core.ToXML LambdaFunctionConfiguration where
  toXML :: LambdaFunctionConfiguration -> XML
toXML LambdaFunctionConfiguration' {[Event]
Maybe Text
Maybe NotificationConfigurationFilter
Text
events :: [Event]
lambdaFunctionArn :: Text
filter' :: Maybe NotificationConfigurationFilter
id :: Maybe Text
$sel:events:LambdaFunctionConfiguration' :: LambdaFunctionConfiguration -> [Event]
$sel:lambdaFunctionArn:LambdaFunctionConfiguration' :: LambdaFunctionConfiguration -> Text
$sel:filter':LambdaFunctionConfiguration' :: LambdaFunctionConfiguration
-> Maybe NotificationConfigurationFilter
$sel:id:LambdaFunctionConfiguration' :: LambdaFunctionConfiguration -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Id" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
id,
        Name
"Filter" Name -> Maybe NotificationConfigurationFilter -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe NotificationConfigurationFilter
filter',
        Name
"CloudFunction" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
lambdaFunctionArn,
        Name -> [Event] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Event" [Event]
events
      ]