{-# 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.CloudFront.Types.LambdaFunctionAssociation
-- 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.CloudFront.Types.LambdaFunctionAssociation where

import Amazonka.CloudFront.Types.EventType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type that contains a Lambda\@Edge function association.
--
-- /See:/ 'newLambdaFunctionAssociation' smart constructor.
data LambdaFunctionAssociation = LambdaFunctionAssociation'
  { -- | A flag that allows a Lambda\@Edge function to have read access to the
    -- body content. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html Accessing the Request Body by Choosing the Include Body Option>
    -- in the Amazon CloudFront Developer Guide.
    LambdaFunctionAssociation -> Maybe Bool
includeBody :: Prelude.Maybe Prelude.Bool,
    -- | The ARN of the Lambda\@Edge function. You must specify the ARN of a
    -- function version; you can\'t specify an alias or $LATEST.
    LambdaFunctionAssociation -> Text
lambdaFunctionARN :: Prelude.Text,
    -- | Specifies the event type that triggers a Lambda\@Edge function
    -- invocation. You can specify the following values:
    --
    -- -   @viewer-request@: The function executes when CloudFront receives a
    --     request from a viewer and before it checks to see whether the
    --     requested object is in the edge cache.
    --
    -- -   @origin-request@: The function executes only when CloudFront sends a
    --     request to your origin. When the requested object is in the edge
    --     cache, the function doesn\'t execute.
    --
    -- -   @origin-response@: The function executes after CloudFront receives a
    --     response from the origin and before it caches the object in the
    --     response. When the requested object is in the edge cache, the
    --     function doesn\'t execute.
    --
    -- -   @viewer-response@: The function executes before CloudFront returns
    --     the requested object to the viewer. The function executes regardless
    --     of whether the object was already in the edge cache.
    --
    --     If the origin returns an HTTP status code other than HTTP 200 (OK),
    --     the function doesn\'t execute.
    LambdaFunctionAssociation -> EventType
eventType :: EventType
  }
  deriving (LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool
(LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool)
-> (LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool)
-> Eq LambdaFunctionAssociation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool
$c/= :: LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool
== :: LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool
$c== :: LambdaFunctionAssociation -> LambdaFunctionAssociation -> Bool
Prelude.Eq, ReadPrec [LambdaFunctionAssociation]
ReadPrec LambdaFunctionAssociation
Int -> ReadS LambdaFunctionAssociation
ReadS [LambdaFunctionAssociation]
(Int -> ReadS LambdaFunctionAssociation)
-> ReadS [LambdaFunctionAssociation]
-> ReadPrec LambdaFunctionAssociation
-> ReadPrec [LambdaFunctionAssociation]
-> Read LambdaFunctionAssociation
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LambdaFunctionAssociation]
$creadListPrec :: ReadPrec [LambdaFunctionAssociation]
readPrec :: ReadPrec LambdaFunctionAssociation
$creadPrec :: ReadPrec LambdaFunctionAssociation
readList :: ReadS [LambdaFunctionAssociation]
$creadList :: ReadS [LambdaFunctionAssociation]
readsPrec :: Int -> ReadS LambdaFunctionAssociation
$creadsPrec :: Int -> ReadS LambdaFunctionAssociation
Prelude.Read, Int -> LambdaFunctionAssociation -> ShowS
[LambdaFunctionAssociation] -> ShowS
LambdaFunctionAssociation -> String
(Int -> LambdaFunctionAssociation -> ShowS)
-> (LambdaFunctionAssociation -> String)
-> ([LambdaFunctionAssociation] -> ShowS)
-> Show LambdaFunctionAssociation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LambdaFunctionAssociation] -> ShowS
$cshowList :: [LambdaFunctionAssociation] -> ShowS
show :: LambdaFunctionAssociation -> String
$cshow :: LambdaFunctionAssociation -> String
showsPrec :: Int -> LambdaFunctionAssociation -> ShowS
$cshowsPrec :: Int -> LambdaFunctionAssociation -> ShowS
Prelude.Show, (forall x.
 LambdaFunctionAssociation -> Rep LambdaFunctionAssociation x)
-> (forall x.
    Rep LambdaFunctionAssociation x -> LambdaFunctionAssociation)
-> Generic LambdaFunctionAssociation
forall x.
Rep LambdaFunctionAssociation x -> LambdaFunctionAssociation
forall x.
LambdaFunctionAssociation -> Rep LambdaFunctionAssociation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep LambdaFunctionAssociation x -> LambdaFunctionAssociation
$cfrom :: forall x.
LambdaFunctionAssociation -> Rep LambdaFunctionAssociation x
Prelude.Generic)

-- |
-- Create a value of 'LambdaFunctionAssociation' 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:
--
-- 'includeBody', 'lambdaFunctionAssociation_includeBody' - A flag that allows a Lambda\@Edge function to have read access to the
-- body content. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html Accessing the Request Body by Choosing the Include Body Option>
-- in the Amazon CloudFront Developer Guide.
--
-- 'lambdaFunctionARN', 'lambdaFunctionAssociation_lambdaFunctionARN' - The ARN of the Lambda\@Edge function. You must specify the ARN of a
-- function version; you can\'t specify an alias or $LATEST.
--
-- 'eventType', 'lambdaFunctionAssociation_eventType' - Specifies the event type that triggers a Lambda\@Edge function
-- invocation. You can specify the following values:
--
-- -   @viewer-request@: The function executes when CloudFront receives a
--     request from a viewer and before it checks to see whether the
--     requested object is in the edge cache.
--
-- -   @origin-request@: The function executes only when CloudFront sends a
--     request to your origin. When the requested object is in the edge
--     cache, the function doesn\'t execute.
--
-- -   @origin-response@: The function executes after CloudFront receives a
--     response from the origin and before it caches the object in the
--     response. When the requested object is in the edge cache, the
--     function doesn\'t execute.
--
-- -   @viewer-response@: The function executes before CloudFront returns
--     the requested object to the viewer. The function executes regardless
--     of whether the object was already in the edge cache.
--
--     If the origin returns an HTTP status code other than HTTP 200 (OK),
--     the function doesn\'t execute.
newLambdaFunctionAssociation ::
  -- | 'lambdaFunctionARN'
  Prelude.Text ->
  -- | 'eventType'
  EventType ->
  LambdaFunctionAssociation
newLambdaFunctionAssociation :: Text -> EventType -> LambdaFunctionAssociation
newLambdaFunctionAssociation
  Text
pLambdaFunctionARN_
  EventType
pEventType_ =
    LambdaFunctionAssociation' :: Maybe Bool -> Text -> EventType -> LambdaFunctionAssociation
LambdaFunctionAssociation'
      { $sel:includeBody:LambdaFunctionAssociation' :: Maybe Bool
includeBody =
          Maybe Bool
forall a. Maybe a
Prelude.Nothing,
        $sel:lambdaFunctionARN:LambdaFunctionAssociation' :: Text
lambdaFunctionARN = Text
pLambdaFunctionARN_,
        $sel:eventType:LambdaFunctionAssociation' :: EventType
eventType = EventType
pEventType_
      }

-- | A flag that allows a Lambda\@Edge function to have read access to the
-- body content. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html Accessing the Request Body by Choosing the Include Body Option>
-- in the Amazon CloudFront Developer Guide.
lambdaFunctionAssociation_includeBody :: Lens.Lens' LambdaFunctionAssociation (Prelude.Maybe Prelude.Bool)
lambdaFunctionAssociation_includeBody :: (Maybe Bool -> f (Maybe Bool))
-> LambdaFunctionAssociation -> f LambdaFunctionAssociation
lambdaFunctionAssociation_includeBody = (LambdaFunctionAssociation -> Maybe Bool)
-> (LambdaFunctionAssociation
    -> Maybe Bool -> LambdaFunctionAssociation)
-> Lens
     LambdaFunctionAssociation
     LambdaFunctionAssociation
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionAssociation' {Maybe Bool
includeBody :: Maybe Bool
$sel:includeBody:LambdaFunctionAssociation' :: LambdaFunctionAssociation -> Maybe Bool
includeBody} -> Maybe Bool
includeBody) (\s :: LambdaFunctionAssociation
s@LambdaFunctionAssociation' {} Maybe Bool
a -> LambdaFunctionAssociation
s {$sel:includeBody:LambdaFunctionAssociation' :: Maybe Bool
includeBody = Maybe Bool
a} :: LambdaFunctionAssociation)

-- | The ARN of the Lambda\@Edge function. You must specify the ARN of a
-- function version; you can\'t specify an alias or $LATEST.
lambdaFunctionAssociation_lambdaFunctionARN :: Lens.Lens' LambdaFunctionAssociation Prelude.Text
lambdaFunctionAssociation_lambdaFunctionARN :: (Text -> f Text)
-> LambdaFunctionAssociation -> f LambdaFunctionAssociation
lambdaFunctionAssociation_lambdaFunctionARN = (LambdaFunctionAssociation -> Text)
-> (LambdaFunctionAssociation -> Text -> LambdaFunctionAssociation)
-> Lens
     LambdaFunctionAssociation LambdaFunctionAssociation Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionAssociation' {Text
lambdaFunctionARN :: Text
$sel:lambdaFunctionARN:LambdaFunctionAssociation' :: LambdaFunctionAssociation -> Text
lambdaFunctionARN} -> Text
lambdaFunctionARN) (\s :: LambdaFunctionAssociation
s@LambdaFunctionAssociation' {} Text
a -> LambdaFunctionAssociation
s {$sel:lambdaFunctionARN:LambdaFunctionAssociation' :: Text
lambdaFunctionARN = Text
a} :: LambdaFunctionAssociation)

-- | Specifies the event type that triggers a Lambda\@Edge function
-- invocation. You can specify the following values:
--
-- -   @viewer-request@: The function executes when CloudFront receives a
--     request from a viewer and before it checks to see whether the
--     requested object is in the edge cache.
--
-- -   @origin-request@: The function executes only when CloudFront sends a
--     request to your origin. When the requested object is in the edge
--     cache, the function doesn\'t execute.
--
-- -   @origin-response@: The function executes after CloudFront receives a
--     response from the origin and before it caches the object in the
--     response. When the requested object is in the edge cache, the
--     function doesn\'t execute.
--
-- -   @viewer-response@: The function executes before CloudFront returns
--     the requested object to the viewer. The function executes regardless
--     of whether the object was already in the edge cache.
--
--     If the origin returns an HTTP status code other than HTTP 200 (OK),
--     the function doesn\'t execute.
lambdaFunctionAssociation_eventType :: Lens.Lens' LambdaFunctionAssociation EventType
lambdaFunctionAssociation_eventType :: (EventType -> f EventType)
-> LambdaFunctionAssociation -> f LambdaFunctionAssociation
lambdaFunctionAssociation_eventType = (LambdaFunctionAssociation -> EventType)
-> (LambdaFunctionAssociation
    -> EventType -> LambdaFunctionAssociation)
-> Lens
     LambdaFunctionAssociation
     LambdaFunctionAssociation
     EventType
     EventType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LambdaFunctionAssociation' {EventType
eventType :: EventType
$sel:eventType:LambdaFunctionAssociation' :: LambdaFunctionAssociation -> EventType
eventType} -> EventType
eventType) (\s :: LambdaFunctionAssociation
s@LambdaFunctionAssociation' {} EventType
a -> LambdaFunctionAssociation
s {$sel:eventType:LambdaFunctionAssociation' :: EventType
eventType = EventType
a} :: LambdaFunctionAssociation)

instance Core.FromXML LambdaFunctionAssociation where
  parseXML :: [Node] -> Either String LambdaFunctionAssociation
parseXML [Node]
x =
    Maybe Bool -> Text -> EventType -> LambdaFunctionAssociation
LambdaFunctionAssociation'
      (Maybe Bool -> Text -> EventType -> LambdaFunctionAssociation)
-> Either String (Maybe Bool)
-> Either String (Text -> EventType -> LambdaFunctionAssociation)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"IncludeBody")
      Either String (Text -> EventType -> LambdaFunctionAssociation)
-> Either String Text
-> Either String (EventType -> LambdaFunctionAssociation)
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
"LambdaFunctionARN")
      Either String (EventType -> LambdaFunctionAssociation)
-> Either String EventType
-> Either String LambdaFunctionAssociation
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String EventType
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"EventType")

instance Prelude.Hashable LambdaFunctionAssociation

instance Prelude.NFData LambdaFunctionAssociation

instance Core.ToXML LambdaFunctionAssociation where
  toXML :: LambdaFunctionAssociation -> XML
toXML LambdaFunctionAssociation' {Maybe Bool
Text
EventType
eventType :: EventType
lambdaFunctionARN :: Text
includeBody :: Maybe Bool
$sel:eventType:LambdaFunctionAssociation' :: LambdaFunctionAssociation -> EventType
$sel:lambdaFunctionARN:LambdaFunctionAssociation' :: LambdaFunctionAssociation -> Text
$sel:includeBody:LambdaFunctionAssociation' :: LambdaFunctionAssociation -> Maybe Bool
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"IncludeBody" Name -> Maybe Bool -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Bool
includeBody,
        Name
"LambdaFunctionARN" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
lambdaFunctionARN,
        Name
"EventType" Name -> EventType -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= EventType
eventType
      ]