{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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.
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'
      { $sel:includeBody:LambdaFunctionAssociation' :: Maybe Bool
includeBody =
          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 :: Lens' LambdaFunctionAssociation (Maybe Bool)
lambdaFunctionAssociation_includeBody = 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 :: Lens' LambdaFunctionAssociation Text
lambdaFunctionAssociation_lambdaFunctionARN = 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 :: Lens' LambdaFunctionAssociation EventType
lambdaFunctionAssociation_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 Data.FromXML LambdaFunctionAssociation where
  parseXML :: [Node] -> Either String LambdaFunctionAssociation
parseXML [Node]
x =
    Maybe Bool -> Text -> EventType -> LambdaFunctionAssociation
LambdaFunctionAssociation'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"IncludeBody")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"LambdaFunctionARN")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"EventType")

instance Prelude.Hashable LambdaFunctionAssociation where
  hashWithSalt :: Int -> LambdaFunctionAssociation -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
includeBody
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
lambdaFunctionARN
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` EventType
eventType

instance Prelude.NFData LambdaFunctionAssociation where
  rnf :: LambdaFunctionAssociation -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
includeBody
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
lambdaFunctionARN
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf EventType
eventType

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"IncludeBody" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Bool
includeBody,
        Name
"LambdaFunctionARN" forall a. ToXML a => Name -> a -> XML
Data.@= Text
lambdaFunctionARN,
        Name
"EventType" forall a. ToXML a => Name -> a -> XML
Data.@= EventType
eventType
      ]