{-# 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.PublishVersion
-- 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)
--
-- Creates a
-- <https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html version>
-- from the current code and configuration of a function. Use versions to
-- create a snapshot of your function code and configuration that doesn\'t
-- change.
--
-- Lambda doesn\'t publish a version if the function\'s configuration and
-- code haven\'t changed since the last version. Use UpdateFunctionCode or
-- UpdateFunctionConfiguration to update the function before publishing a
-- version.
--
-- Clients can invoke versions directly or with an alias. To create an
-- alias, use CreateAlias.
module Amazonka.Lambda.PublishVersion
  ( -- * Creating a Request
    PublishVersion (..),
    newPublishVersion,

    -- * Request Lenses
    publishVersion_codeSha256,
    publishVersion_description,
    publishVersion_revisionId,
    publishVersion_functionName,

    -- * Destructuring the Response
    FunctionConfiguration (..),
    newFunctionConfiguration,

    -- * Response Lenses
    functionConfiguration_memorySize,
    functionConfiguration_runtime,
    functionConfiguration_state,
    functionConfiguration_signingProfileVersionArn,
    functionConfiguration_lastUpdateStatus,
    functionConfiguration_functionArn,
    functionConfiguration_kmsKeyArn,
    functionConfiguration_packageType,
    functionConfiguration_fileSystemConfigs,
    functionConfiguration_environment,
    functionConfiguration_deadLetterConfig,
    functionConfiguration_architectures,
    functionConfiguration_signingJobArn,
    functionConfiguration_role,
    functionConfiguration_vpcConfig,
    functionConfiguration_version,
    functionConfiguration_functionName,
    functionConfiguration_layers,
    functionConfiguration_codeSize,
    functionConfiguration_handler,
    functionConfiguration_timeout,
    functionConfiguration_lastUpdateStatusReason,
    functionConfiguration_stateReason,
    functionConfiguration_lastModified,
    functionConfiguration_codeSha256,
    functionConfiguration_tracingConfig,
    functionConfiguration_stateReasonCode,
    functionConfiguration_imageConfigResponse,
    functionConfiguration_description,
    functionConfiguration_lastUpdateStatusReasonCode,
    functionConfiguration_revisionId,
    functionConfiguration_masterArn,
  )
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:/ 'newPublishVersion' smart constructor.
data PublishVersion = PublishVersion'
  { -- | Only publish a version if the hash value matches the value that\'s
    -- specified. Use this option to avoid publishing a version if the function
    -- code has changed since you last updated it. You can get the hash for the
    -- version that you uploaded from the output of UpdateFunctionCode.
    PublishVersion -> Maybe Text
codeSha256 :: Prelude.Maybe Prelude.Text,
    -- | A description for the version to override the description in the
    -- function configuration.
    PublishVersion -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | Only update the function if the revision ID matches the ID that\'s
    -- specified. Use this option to avoid publishing a version if the function
    -- configuration has changed since you last updated it.
    PublishVersion -> 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.
    PublishVersion -> Text
functionName :: Prelude.Text
  }
  deriving (PublishVersion -> PublishVersion -> Bool
(PublishVersion -> PublishVersion -> Bool)
-> (PublishVersion -> PublishVersion -> Bool) -> Eq PublishVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PublishVersion -> PublishVersion -> Bool
$c/= :: PublishVersion -> PublishVersion -> Bool
== :: PublishVersion -> PublishVersion -> Bool
$c== :: PublishVersion -> PublishVersion -> Bool
Prelude.Eq, ReadPrec [PublishVersion]
ReadPrec PublishVersion
Int -> ReadS PublishVersion
ReadS [PublishVersion]
(Int -> ReadS PublishVersion)
-> ReadS [PublishVersion]
-> ReadPrec PublishVersion
-> ReadPrec [PublishVersion]
-> Read PublishVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PublishVersion]
$creadListPrec :: ReadPrec [PublishVersion]
readPrec :: ReadPrec PublishVersion
$creadPrec :: ReadPrec PublishVersion
readList :: ReadS [PublishVersion]
$creadList :: ReadS [PublishVersion]
readsPrec :: Int -> ReadS PublishVersion
$creadsPrec :: Int -> ReadS PublishVersion
Prelude.Read, Int -> PublishVersion -> ShowS
[PublishVersion] -> ShowS
PublishVersion -> String
(Int -> PublishVersion -> ShowS)
-> (PublishVersion -> String)
-> ([PublishVersion] -> ShowS)
-> Show PublishVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PublishVersion] -> ShowS
$cshowList :: [PublishVersion] -> ShowS
show :: PublishVersion -> String
$cshow :: PublishVersion -> String
showsPrec :: Int -> PublishVersion -> ShowS
$cshowsPrec :: Int -> PublishVersion -> ShowS
Prelude.Show, (forall x. PublishVersion -> Rep PublishVersion x)
-> (forall x. Rep PublishVersion x -> PublishVersion)
-> Generic PublishVersion
forall x. Rep PublishVersion x -> PublishVersion
forall x. PublishVersion -> Rep PublishVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PublishVersion x -> PublishVersion
$cfrom :: forall x. PublishVersion -> Rep PublishVersion x
Prelude.Generic)

-- |
-- Create a value of 'PublishVersion' 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:
--
-- 'codeSha256', 'publishVersion_codeSha256' - Only publish a version if the hash value matches the value that\'s
-- specified. Use this option to avoid publishing a version if the function
-- code has changed since you last updated it. You can get the hash for the
-- version that you uploaded from the output of UpdateFunctionCode.
--
-- 'description', 'publishVersion_description' - A description for the version to override the description in the
-- function configuration.
--
-- 'revisionId', 'publishVersion_revisionId' - Only update the function if the revision ID matches the ID that\'s
-- specified. Use this option to avoid publishing a version if the function
-- configuration has changed since you last updated it.
--
-- 'functionName', 'publishVersion_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.
newPublishVersion ::
  -- | 'functionName'
  Prelude.Text ->
  PublishVersion
newPublishVersion :: Text -> PublishVersion
newPublishVersion Text
pFunctionName_ =
  PublishVersion' :: Maybe Text -> Maybe Text -> Maybe Text -> Text -> PublishVersion
PublishVersion'
    { $sel:codeSha256:PublishVersion' :: Maybe Text
codeSha256 = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:PublishVersion' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:revisionId:PublishVersion' :: Maybe Text
revisionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionName:PublishVersion' :: Text
functionName = Text
pFunctionName_
    }

-- | Only publish a version if the hash value matches the value that\'s
-- specified. Use this option to avoid publishing a version if the function
-- code has changed since you last updated it. You can get the hash for the
-- version that you uploaded from the output of UpdateFunctionCode.
publishVersion_codeSha256 :: Lens.Lens' PublishVersion (Prelude.Maybe Prelude.Text)
publishVersion_codeSha256 :: (Maybe Text -> f (Maybe Text))
-> PublishVersion -> f PublishVersion
publishVersion_codeSha256 = (PublishVersion -> Maybe Text)
-> (PublishVersion -> Maybe Text -> PublishVersion)
-> Lens PublishVersion PublishVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishVersion' {Maybe Text
codeSha256 :: Maybe Text
$sel:codeSha256:PublishVersion' :: PublishVersion -> Maybe Text
codeSha256} -> Maybe Text
codeSha256) (\s :: PublishVersion
s@PublishVersion' {} Maybe Text
a -> PublishVersion
s {$sel:codeSha256:PublishVersion' :: Maybe Text
codeSha256 = Maybe Text
a} :: PublishVersion)

-- | A description for the version to override the description in the
-- function configuration.
publishVersion_description :: Lens.Lens' PublishVersion (Prelude.Maybe Prelude.Text)
publishVersion_description :: (Maybe Text -> f (Maybe Text))
-> PublishVersion -> f PublishVersion
publishVersion_description = (PublishVersion -> Maybe Text)
-> (PublishVersion -> Maybe Text -> PublishVersion)
-> Lens PublishVersion PublishVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishVersion' {Maybe Text
description :: Maybe Text
$sel:description:PublishVersion' :: PublishVersion -> Maybe Text
description} -> Maybe Text
description) (\s :: PublishVersion
s@PublishVersion' {} Maybe Text
a -> PublishVersion
s {$sel:description:PublishVersion' :: Maybe Text
description = Maybe Text
a} :: PublishVersion)

-- | Only update the function if the revision ID matches the ID that\'s
-- specified. Use this option to avoid publishing a version if the function
-- configuration has changed since you last updated it.
publishVersion_revisionId :: Lens.Lens' PublishVersion (Prelude.Maybe Prelude.Text)
publishVersion_revisionId :: (Maybe Text -> f (Maybe Text))
-> PublishVersion -> f PublishVersion
publishVersion_revisionId = (PublishVersion -> Maybe Text)
-> (PublishVersion -> Maybe Text -> PublishVersion)
-> Lens PublishVersion PublishVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishVersion' {Maybe Text
revisionId :: Maybe Text
$sel:revisionId:PublishVersion' :: PublishVersion -> Maybe Text
revisionId} -> Maybe Text
revisionId) (\s :: PublishVersion
s@PublishVersion' {} Maybe Text
a -> PublishVersion
s {$sel:revisionId:PublishVersion' :: Maybe Text
revisionId = Maybe Text
a} :: PublishVersion)

-- | 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.
publishVersion_functionName :: Lens.Lens' PublishVersion Prelude.Text
publishVersion_functionName :: (Text -> f Text) -> PublishVersion -> f PublishVersion
publishVersion_functionName = (PublishVersion -> Text)
-> (PublishVersion -> Text -> PublishVersion)
-> Lens PublishVersion PublishVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishVersion' {Text
functionName :: Text
$sel:functionName:PublishVersion' :: PublishVersion -> Text
functionName} -> Text
functionName) (\s :: PublishVersion
s@PublishVersion' {} Text
a -> PublishVersion
s {$sel:functionName:PublishVersion' :: Text
functionName = Text
a} :: PublishVersion)

instance Core.AWSRequest PublishVersion where
  type
    AWSResponse PublishVersion =
      FunctionConfiguration
  request :: PublishVersion -> Request PublishVersion
request = Service -> PublishVersion -> Request PublishVersion
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PublishVersion
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PublishVersion)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PublishVersion))
-> Logger
-> Service
-> Proxy PublishVersion
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PublishVersion)))
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 FunctionConfiguration
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable PublishVersion

instance Prelude.NFData PublishVersion

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

instance Core.ToJSON PublishVersion where
  toJSON :: PublishVersion -> Value
toJSON PublishVersion' {Maybe Text
Text
functionName :: Text
revisionId :: Maybe Text
description :: Maybe Text
codeSha256 :: Maybe Text
$sel:functionName:PublishVersion' :: PublishVersion -> Text
$sel:revisionId:PublishVersion' :: PublishVersion -> Maybe Text
$sel:description:PublishVersion' :: PublishVersion -> Maybe Text
$sel:codeSha256:PublishVersion' :: PublishVersion -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CodeSha256" 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
codeSha256,
            (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 PublishVersion where
  toPath :: PublishVersion -> ByteString
toPath PublishVersion' {Maybe Text
Text
functionName :: Text
revisionId :: Maybe Text
description :: Maybe Text
codeSha256 :: Maybe Text
$sel:functionName:PublishVersion' :: PublishVersion -> Text
$sel:revisionId:PublishVersion' :: PublishVersion -> Maybe Text
$sel:description:PublishVersion' :: PublishVersion -> Maybe Text
$sel:codeSha256:PublishVersion' :: PublishVersion -> Maybe Text
..} =
    [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
"/versions"
      ]

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