{-# 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.PutFunctionConcurrency
-- 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)
--
-- Sets the maximum number of simultaneous executions for a function, and
-- reserves capacity for that concurrency level.
--
-- Concurrency settings apply to the function as a whole, including all
-- published versions and the unpublished version. Reserving concurrency
-- both ensures that your function has capacity to process the specified
-- number of events simultaneously, and prevents it from scaling beyond
-- that level. Use GetFunction to see the current setting for a function.
--
-- Use GetAccountSettings to see your Regional concurrency limit. You can
-- reserve concurrency for as many functions as you like, as long as you
-- leave at least 100 simultaneous executions unreserved for functions that
-- aren\'t configured with a per-function limit. For more information, see
-- <https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html Managing Concurrency>.
module Amazonka.Lambda.PutFunctionConcurrency
  ( -- * Creating a Request
    PutFunctionConcurrency (..),
    newPutFunctionConcurrency,

    -- * Request Lenses
    putFunctionConcurrency_functionName,
    putFunctionConcurrency_reservedConcurrentExecutions,

    -- * Destructuring the Response
    Concurrency (..),
    newConcurrency,

    -- * Response Lenses
    concurrency_reservedConcurrentExecutions,
  )
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:/ 'newPutFunctionConcurrency' smart constructor.
data PutFunctionConcurrency = PutFunctionConcurrency'
  { -- | The name of the Lambda function.
    --
    -- __Name formats__
    --
    -- -   __Function name__ - @my-function@.
    --
    -- -   __Function ARN__ -
    --     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
    --
    -- -   __Partial ARN__ - @123456789012:function:my-function@.
    --
    -- The length constraint applies only to the full ARN. If you specify only
    -- the function name, it is limited to 64 characters in length.
    PutFunctionConcurrency -> Text
functionName :: Prelude.Text,
    -- | The number of simultaneous executions to reserve for the function.
    PutFunctionConcurrency -> Natural
reservedConcurrentExecutions :: Prelude.Natural
  }
  deriving (PutFunctionConcurrency -> PutFunctionConcurrency -> Bool
(PutFunctionConcurrency -> PutFunctionConcurrency -> Bool)
-> (PutFunctionConcurrency -> PutFunctionConcurrency -> Bool)
-> Eq PutFunctionConcurrency
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutFunctionConcurrency -> PutFunctionConcurrency -> Bool
$c/= :: PutFunctionConcurrency -> PutFunctionConcurrency -> Bool
== :: PutFunctionConcurrency -> PutFunctionConcurrency -> Bool
$c== :: PutFunctionConcurrency -> PutFunctionConcurrency -> Bool
Prelude.Eq, ReadPrec [PutFunctionConcurrency]
ReadPrec PutFunctionConcurrency
Int -> ReadS PutFunctionConcurrency
ReadS [PutFunctionConcurrency]
(Int -> ReadS PutFunctionConcurrency)
-> ReadS [PutFunctionConcurrency]
-> ReadPrec PutFunctionConcurrency
-> ReadPrec [PutFunctionConcurrency]
-> Read PutFunctionConcurrency
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutFunctionConcurrency]
$creadListPrec :: ReadPrec [PutFunctionConcurrency]
readPrec :: ReadPrec PutFunctionConcurrency
$creadPrec :: ReadPrec PutFunctionConcurrency
readList :: ReadS [PutFunctionConcurrency]
$creadList :: ReadS [PutFunctionConcurrency]
readsPrec :: Int -> ReadS PutFunctionConcurrency
$creadsPrec :: Int -> ReadS PutFunctionConcurrency
Prelude.Read, Int -> PutFunctionConcurrency -> ShowS
[PutFunctionConcurrency] -> ShowS
PutFunctionConcurrency -> String
(Int -> PutFunctionConcurrency -> ShowS)
-> (PutFunctionConcurrency -> String)
-> ([PutFunctionConcurrency] -> ShowS)
-> Show PutFunctionConcurrency
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutFunctionConcurrency] -> ShowS
$cshowList :: [PutFunctionConcurrency] -> ShowS
show :: PutFunctionConcurrency -> String
$cshow :: PutFunctionConcurrency -> String
showsPrec :: Int -> PutFunctionConcurrency -> ShowS
$cshowsPrec :: Int -> PutFunctionConcurrency -> ShowS
Prelude.Show, (forall x. PutFunctionConcurrency -> Rep PutFunctionConcurrency x)
-> (forall x.
    Rep PutFunctionConcurrency x -> PutFunctionConcurrency)
-> Generic PutFunctionConcurrency
forall x. Rep PutFunctionConcurrency x -> PutFunctionConcurrency
forall x. PutFunctionConcurrency -> Rep PutFunctionConcurrency x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutFunctionConcurrency x -> PutFunctionConcurrency
$cfrom :: forall x. PutFunctionConcurrency -> Rep PutFunctionConcurrency x
Prelude.Generic)

-- |
-- Create a value of 'PutFunctionConcurrency' 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:
--
-- 'functionName', 'putFunctionConcurrency_functionName' - The name of the Lambda function.
--
-- __Name formats__
--
-- -   __Function name__ - @my-function@.
--
-- -   __Function ARN__ -
--     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
--
-- -   __Partial ARN__ - @123456789012:function:my-function@.
--
-- The length constraint applies only to the full ARN. If you specify only
-- the function name, it is limited to 64 characters in length.
--
-- 'reservedConcurrentExecutions', 'putFunctionConcurrency_reservedConcurrentExecutions' - The number of simultaneous executions to reserve for the function.
newPutFunctionConcurrency ::
  -- | 'functionName'
  Prelude.Text ->
  -- | 'reservedConcurrentExecutions'
  Prelude.Natural ->
  PutFunctionConcurrency
newPutFunctionConcurrency :: Text -> Natural -> PutFunctionConcurrency
newPutFunctionConcurrency
  Text
pFunctionName_
  Natural
pReservedConcurrentExecutions_ =
    PutFunctionConcurrency' :: Text -> Natural -> PutFunctionConcurrency
PutFunctionConcurrency'
      { $sel:functionName:PutFunctionConcurrency' :: Text
functionName =
          Text
pFunctionName_,
        $sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: Natural
reservedConcurrentExecutions =
          Natural
pReservedConcurrentExecutions_
      }

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

-- | The number of simultaneous executions to reserve for the function.
putFunctionConcurrency_reservedConcurrentExecutions :: Lens.Lens' PutFunctionConcurrency Prelude.Natural
putFunctionConcurrency_reservedConcurrentExecutions :: (Natural -> f Natural)
-> PutFunctionConcurrency -> f PutFunctionConcurrency
putFunctionConcurrency_reservedConcurrentExecutions = (PutFunctionConcurrency -> Natural)
-> (PutFunctionConcurrency -> Natural -> PutFunctionConcurrency)
-> Lens
     PutFunctionConcurrency PutFunctionConcurrency Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutFunctionConcurrency' {Natural
reservedConcurrentExecutions :: Natural
$sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: PutFunctionConcurrency -> Natural
reservedConcurrentExecutions} -> Natural
reservedConcurrentExecutions) (\s :: PutFunctionConcurrency
s@PutFunctionConcurrency' {} Natural
a -> PutFunctionConcurrency
s {$sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: Natural
reservedConcurrentExecutions = Natural
a} :: PutFunctionConcurrency)

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

instance Prelude.Hashable PutFunctionConcurrency

instance Prelude.NFData PutFunctionConcurrency

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

instance Core.ToJSON PutFunctionConcurrency where
  toJSON :: PutFunctionConcurrency -> Value
toJSON PutFunctionConcurrency' {Natural
Text
reservedConcurrentExecutions :: Natural
functionName :: Text
$sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: PutFunctionConcurrency -> Natural
$sel:functionName:PutFunctionConcurrency' :: PutFunctionConcurrency -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"ReservedConcurrentExecutions"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
reservedConcurrentExecutions
              )
          ]
      )

instance Core.ToPath PutFunctionConcurrency where
  toPath :: PutFunctionConcurrency -> ByteString
toPath PutFunctionConcurrency' {Natural
Text
reservedConcurrentExecutions :: Natural
functionName :: Text
$sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: PutFunctionConcurrency -> Natural
$sel:functionName:PutFunctionConcurrency' :: PutFunctionConcurrency -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2017-10-31/functions/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
functionName,
        ByteString
"/concurrency"
      ]

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