{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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_architectures,
    functionConfiguration_codeSha256,
    functionConfiguration_codeSize,
    functionConfiguration_deadLetterConfig,
    functionConfiguration_description,
    functionConfiguration_environment,
    functionConfiguration_ephemeralStorage,
    functionConfiguration_fileSystemConfigs,
    functionConfiguration_functionArn,
    functionConfiguration_functionName,
    functionConfiguration_handler,
    functionConfiguration_imageConfigResponse,
    functionConfiguration_kmsKeyArn,
    functionConfiguration_lastModified,
    functionConfiguration_lastUpdateStatus,
    functionConfiguration_lastUpdateStatusReason,
    functionConfiguration_lastUpdateStatusReasonCode,
    functionConfiguration_layers,
    functionConfiguration_masterArn,
    functionConfiguration_memorySize,
    functionConfiguration_packageType,
    functionConfiguration_revisionId,
    functionConfiguration_role,
    functionConfiguration_runtime,
    functionConfiguration_signingJobArn,
    functionConfiguration_signingProfileVersionArn,
    functionConfiguration_snapStart,
    functionConfiguration_state,
    functionConfiguration_stateReason,
    functionConfiguration_stateReasonCode,
    functionConfiguration_timeout,
    functionConfiguration_tracingConfig,
    functionConfiguration_version,
    functionConfiguration_vpcConfig,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lambda.Types
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
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]
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
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. 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'
    { $sel:codeSha256:PublishVersion' :: Maybe Text
codeSha256 = forall a. Maybe a
Prelude.Nothing,
      $sel:description:PublishVersion' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:revisionId:PublishVersion' :: Maybe Text
revisionId = 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 :: Lens' PublishVersion (Maybe Text)
publishVersion_codeSha256 = 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 :: Lens' PublishVersion (Maybe Text)
publishVersion_description = 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 :: Lens' PublishVersion (Maybe Text)
publishVersion_revisionId = 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 :: Lens' PublishVersion Text
publishVersion_functionName = 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 :: (Service -> Service) -> PublishVersion -> Request PublishVersion
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PublishVersion
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PublishVersion)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> forall a. FromJSON a => Object -> Either String a
Data.eitherParseJSON Object
x)

instance Prelude.Hashable PublishVersion where
  hashWithSalt :: Int -> PublishVersion -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
codeSha256
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
revisionId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
functionName

instance Prelude.NFData PublishVersion where
  rnf :: PublishVersion -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
codeSha256
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
revisionId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
functionName

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CodeSha256" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
codeSha256,
            (Key
"Description" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            (Key
"RevisionId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
revisionId
          ]
      )

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2015-03-31/functions/",
        forall a. ToByteString a => a -> ByteString
Data.toBS Text
functionName,
        ByteString
"/versions"
      ]

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