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

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

-- |
-- Module      : Amazonka.Lambda.UpdateAlias
-- 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)
--
-- Updates the configuration of a Lambda function
-- <https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html alias>.
module Amazonka.Lambda.UpdateAlias
  ( -- * Creating a Request
    UpdateAlias (..),
    newUpdateAlias,

    -- * Request Lenses
    updateAlias_routingConfig,
    updateAlias_functionVersion,
    updateAlias_description,
    updateAlias_revisionId,
    updateAlias_functionName,
    updateAlias_name,

    -- * Destructuring the Response
    AliasConfiguration (..),
    newAliasConfiguration,

    -- * Response Lenses
    aliasConfiguration_routingConfig,
    aliasConfiguration_name,
    aliasConfiguration_functionVersion,
    aliasConfiguration_aliasArn,
    aliasConfiguration_description,
    aliasConfiguration_revisionId,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.Lambda.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUpdateAlias' smart constructor.
data UpdateAlias = UpdateAlias'
  { -- | The
    -- <https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing routing configuration>
    -- of the alias.
    UpdateAlias -> Maybe AliasRoutingConfiguration
routingConfig :: Prelude.Maybe AliasRoutingConfiguration,
    -- | The function version that the alias invokes.
    UpdateAlias -> Maybe Text
functionVersion :: Prelude.Maybe Prelude.Text,
    -- | A description of the alias.
    UpdateAlias -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | Only update the alias if the revision ID matches the ID that\'s
    -- specified. Use this option to avoid modifying an alias that has changed
    -- since you last read it.
    UpdateAlias -> Maybe Text
revisionId :: Prelude.Maybe Prelude.Text,
    -- | The name of the Lambda function.
    --
    -- __Name formats__
    --
    -- -   __Function name__ - @MyFunction@.
    --
    -- -   __Function ARN__ -
    --     @arn:aws:lambda:us-west-2:123456789012:function:MyFunction@.
    --
    -- -   __Partial ARN__ - @123456789012:function:MyFunction@.
    --
    -- The length constraint applies only to the full ARN. If you specify only
    -- the function name, it is limited to 64 characters in length.
    UpdateAlias -> Text
functionName :: Prelude.Text,
    -- | The name of the alias.
    UpdateAlias -> Text
name :: Prelude.Text
  }
  deriving (UpdateAlias -> UpdateAlias -> Bool
(UpdateAlias -> UpdateAlias -> Bool)
-> (UpdateAlias -> UpdateAlias -> Bool) -> Eq UpdateAlias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateAlias -> UpdateAlias -> Bool
$c/= :: UpdateAlias -> UpdateAlias -> Bool
== :: UpdateAlias -> UpdateAlias -> Bool
$c== :: UpdateAlias -> UpdateAlias -> Bool
Prelude.Eq, ReadPrec [UpdateAlias]
ReadPrec UpdateAlias
Int -> ReadS UpdateAlias
ReadS [UpdateAlias]
(Int -> ReadS UpdateAlias)
-> ReadS [UpdateAlias]
-> ReadPrec UpdateAlias
-> ReadPrec [UpdateAlias]
-> Read UpdateAlias
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateAlias]
$creadListPrec :: ReadPrec [UpdateAlias]
readPrec :: ReadPrec UpdateAlias
$creadPrec :: ReadPrec UpdateAlias
readList :: ReadS [UpdateAlias]
$creadList :: ReadS [UpdateAlias]
readsPrec :: Int -> ReadS UpdateAlias
$creadsPrec :: Int -> ReadS UpdateAlias
Prelude.Read, Int -> UpdateAlias -> ShowS
[UpdateAlias] -> ShowS
UpdateAlias -> String
(Int -> UpdateAlias -> ShowS)
-> (UpdateAlias -> String)
-> ([UpdateAlias] -> ShowS)
-> Show UpdateAlias
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateAlias] -> ShowS
$cshowList :: [UpdateAlias] -> ShowS
show :: UpdateAlias -> String
$cshow :: UpdateAlias -> String
showsPrec :: Int -> UpdateAlias -> ShowS
$cshowsPrec :: Int -> UpdateAlias -> ShowS
Prelude.Show, (forall x. UpdateAlias -> Rep UpdateAlias x)
-> (forall x. Rep UpdateAlias x -> UpdateAlias)
-> Generic UpdateAlias
forall x. Rep UpdateAlias x -> UpdateAlias
forall x. UpdateAlias -> Rep UpdateAlias x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateAlias x -> UpdateAlias
$cfrom :: forall x. UpdateAlias -> Rep UpdateAlias x
Prelude.Generic)

-- |
-- Create a value of 'UpdateAlias' 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:
--
-- 'routingConfig', 'updateAlias_routingConfig' - The
-- <https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing routing configuration>
-- of the alias.
--
-- 'functionVersion', 'updateAlias_functionVersion' - The function version that the alias invokes.
--
-- 'description', 'updateAlias_description' - A description of the alias.
--
-- 'revisionId', 'updateAlias_revisionId' - Only update the alias if the revision ID matches the ID that\'s
-- specified. Use this option to avoid modifying an alias that has changed
-- since you last read it.
--
-- 'functionName', 'updateAlias_functionName' - The name of the Lambda function.
--
-- __Name formats__
--
-- -   __Function name__ - @MyFunction@.
--
-- -   __Function ARN__ -
--     @arn:aws:lambda:us-west-2:123456789012:function:MyFunction@.
--
-- -   __Partial ARN__ - @123456789012:function:MyFunction@.
--
-- The length constraint applies only to the full ARN. If you specify only
-- the function name, it is limited to 64 characters in length.
--
-- 'name', 'updateAlias_name' - The name of the alias.
newUpdateAlias ::
  -- | 'functionName'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  UpdateAlias
newUpdateAlias :: Text -> Text -> UpdateAlias
newUpdateAlias Text
pFunctionName_ Text
pName_ =
  UpdateAlias' :: Maybe AliasRoutingConfiguration
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Text
-> Text
-> UpdateAlias
UpdateAlias'
    { $sel:routingConfig:UpdateAlias' :: Maybe AliasRoutingConfiguration
routingConfig = Maybe AliasRoutingConfiguration
forall a. Maybe a
Prelude.Nothing,
      $sel:functionVersion:UpdateAlias' :: Maybe Text
functionVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:UpdateAlias' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:revisionId:UpdateAlias' :: Maybe Text
revisionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionName:UpdateAlias' :: Text
functionName = Text
pFunctionName_,
      $sel:name:UpdateAlias' :: Text
name = Text
pName_
    }

-- | The
-- <https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html#configuring-alias-routing routing configuration>
-- of the alias.
updateAlias_routingConfig :: Lens.Lens' UpdateAlias (Prelude.Maybe AliasRoutingConfiguration)
updateAlias_routingConfig :: (Maybe AliasRoutingConfiguration
 -> f (Maybe AliasRoutingConfiguration))
-> UpdateAlias -> f UpdateAlias
updateAlias_routingConfig = (UpdateAlias -> Maybe AliasRoutingConfiguration)
-> (UpdateAlias -> Maybe AliasRoutingConfiguration -> UpdateAlias)
-> Lens
     UpdateAlias
     UpdateAlias
     (Maybe AliasRoutingConfiguration)
     (Maybe AliasRoutingConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAlias' {Maybe AliasRoutingConfiguration
routingConfig :: Maybe AliasRoutingConfiguration
$sel:routingConfig:UpdateAlias' :: UpdateAlias -> Maybe AliasRoutingConfiguration
routingConfig} -> Maybe AliasRoutingConfiguration
routingConfig) (\s :: UpdateAlias
s@UpdateAlias' {} Maybe AliasRoutingConfiguration
a -> UpdateAlias
s {$sel:routingConfig:UpdateAlias' :: Maybe AliasRoutingConfiguration
routingConfig = Maybe AliasRoutingConfiguration
a} :: UpdateAlias)

-- | The function version that the alias invokes.
updateAlias_functionVersion :: Lens.Lens' UpdateAlias (Prelude.Maybe Prelude.Text)
updateAlias_functionVersion :: (Maybe Text -> f (Maybe Text)) -> UpdateAlias -> f UpdateAlias
updateAlias_functionVersion = (UpdateAlias -> Maybe Text)
-> (UpdateAlias -> Maybe Text -> UpdateAlias)
-> Lens UpdateAlias UpdateAlias (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAlias' {Maybe Text
functionVersion :: Maybe Text
$sel:functionVersion:UpdateAlias' :: UpdateAlias -> Maybe Text
functionVersion} -> Maybe Text
functionVersion) (\s :: UpdateAlias
s@UpdateAlias' {} Maybe Text
a -> UpdateAlias
s {$sel:functionVersion:UpdateAlias' :: Maybe Text
functionVersion = Maybe Text
a} :: UpdateAlias)

-- | A description of the alias.
updateAlias_description :: Lens.Lens' UpdateAlias (Prelude.Maybe Prelude.Text)
updateAlias_description :: (Maybe Text -> f (Maybe Text)) -> UpdateAlias -> f UpdateAlias
updateAlias_description = (UpdateAlias -> Maybe Text)
-> (UpdateAlias -> Maybe Text -> UpdateAlias)
-> Lens UpdateAlias UpdateAlias (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAlias' {Maybe Text
description :: Maybe Text
$sel:description:UpdateAlias' :: UpdateAlias -> Maybe Text
description} -> Maybe Text
description) (\s :: UpdateAlias
s@UpdateAlias' {} Maybe Text
a -> UpdateAlias
s {$sel:description:UpdateAlias' :: Maybe Text
description = Maybe Text
a} :: UpdateAlias)

-- | Only update the alias if the revision ID matches the ID that\'s
-- specified. Use this option to avoid modifying an alias that has changed
-- since you last read it.
updateAlias_revisionId :: Lens.Lens' UpdateAlias (Prelude.Maybe Prelude.Text)
updateAlias_revisionId :: (Maybe Text -> f (Maybe Text)) -> UpdateAlias -> f UpdateAlias
updateAlias_revisionId = (UpdateAlias -> Maybe Text)
-> (UpdateAlias -> Maybe Text -> UpdateAlias)
-> Lens UpdateAlias UpdateAlias (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAlias' {Maybe Text
revisionId :: Maybe Text
$sel:revisionId:UpdateAlias' :: UpdateAlias -> Maybe Text
revisionId} -> Maybe Text
revisionId) (\s :: UpdateAlias
s@UpdateAlias' {} Maybe Text
a -> UpdateAlias
s {$sel:revisionId:UpdateAlias' :: Maybe Text
revisionId = Maybe Text
a} :: UpdateAlias)

-- | The name of the Lambda function.
--
-- __Name formats__
--
-- -   __Function name__ - @MyFunction@.
--
-- -   __Function ARN__ -
--     @arn:aws:lambda:us-west-2:123456789012:function:MyFunction@.
--
-- -   __Partial ARN__ - @123456789012:function:MyFunction@.
--
-- The length constraint applies only to the full ARN. If you specify only
-- the function name, it is limited to 64 characters in length.
updateAlias_functionName :: Lens.Lens' UpdateAlias Prelude.Text
updateAlias_functionName :: (Text -> f Text) -> UpdateAlias -> f UpdateAlias
updateAlias_functionName = (UpdateAlias -> Text)
-> (UpdateAlias -> Text -> UpdateAlias)
-> Lens UpdateAlias UpdateAlias Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAlias' {Text
functionName :: Text
$sel:functionName:UpdateAlias' :: UpdateAlias -> Text
functionName} -> Text
functionName) (\s :: UpdateAlias
s@UpdateAlias' {} Text
a -> UpdateAlias
s {$sel:functionName:UpdateAlias' :: Text
functionName = Text
a} :: UpdateAlias)

-- | The name of the alias.
updateAlias_name :: Lens.Lens' UpdateAlias Prelude.Text
updateAlias_name :: (Text -> f Text) -> UpdateAlias -> f UpdateAlias
updateAlias_name = (UpdateAlias -> Text)
-> (UpdateAlias -> Text -> UpdateAlias)
-> Lens UpdateAlias UpdateAlias Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateAlias' {Text
name :: Text
$sel:name:UpdateAlias' :: UpdateAlias -> Text
name} -> Text
name) (\s :: UpdateAlias
s@UpdateAlias' {} Text
a -> UpdateAlias
s {$sel:name:UpdateAlias' :: Text
name = Text
a} :: UpdateAlias)

instance Core.AWSRequest UpdateAlias where
  type AWSResponse UpdateAlias = AliasConfiguration
  request :: UpdateAlias -> Request UpdateAlias
request = Service -> UpdateAlias -> Request UpdateAlias
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateAlias
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateAlias)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateAlias))
-> Logger
-> Service
-> Proxy UpdateAlias
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateAlias)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String AliasConfiguration
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable UpdateAlias

instance Prelude.NFData UpdateAlias

instance Core.ToHeaders UpdateAlias where
  toHeaders :: UpdateAlias -> ResponseHeaders
toHeaders = ResponseHeaders -> UpdateAlias -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON UpdateAlias where
  toJSON :: UpdateAlias -> Value
toJSON UpdateAlias' {Maybe Text
Maybe AliasRoutingConfiguration
Text
name :: Text
functionName :: Text
revisionId :: Maybe Text
description :: Maybe Text
functionVersion :: Maybe Text
routingConfig :: Maybe AliasRoutingConfiguration
$sel:name:UpdateAlias' :: UpdateAlias -> Text
$sel:functionName:UpdateAlias' :: UpdateAlias -> Text
$sel:revisionId:UpdateAlias' :: UpdateAlias -> Maybe Text
$sel:description:UpdateAlias' :: UpdateAlias -> Maybe Text
$sel:functionVersion:UpdateAlias' :: UpdateAlias -> Maybe Text
$sel:routingConfig:UpdateAlias' :: UpdateAlias -> Maybe AliasRoutingConfiguration
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"RoutingConfig" Text -> AliasRoutingConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (AliasRoutingConfiguration -> Pair)
-> Maybe AliasRoutingConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AliasRoutingConfiguration
routingConfig,
            (Text
"FunctionVersion" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
functionVersion,
            (Text
"Description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            (Text
"RevisionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
revisionId
          ]
      )

instance Core.ToPath UpdateAlias where
  toPath :: UpdateAlias -> ByteString
toPath UpdateAlias' {Maybe Text
Maybe AliasRoutingConfiguration
Text
name :: Text
functionName :: Text
revisionId :: Maybe Text
description :: Maybe Text
functionVersion :: Maybe Text
routingConfig :: Maybe AliasRoutingConfiguration
$sel:name:UpdateAlias' :: UpdateAlias -> Text
$sel:functionName:UpdateAlias' :: UpdateAlias -> Text
$sel:revisionId:UpdateAlias' :: UpdateAlias -> Maybe Text
$sel:description:UpdateAlias' :: UpdateAlias -> Maybe Text
$sel:functionVersion:UpdateAlias' :: UpdateAlias -> Maybe Text
$sel:routingConfig:UpdateAlias' :: UpdateAlias -> Maybe AliasRoutingConfiguration
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2015-03-31/functions/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
functionName,
        ByteString
"/aliases/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
name
      ]

instance Core.ToQuery UpdateAlias where
  toQuery :: UpdateAlias -> QueryString
toQuery = QueryString -> UpdateAlias -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty