{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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/invocation-scaling.html Lambda function scaling>.
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 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:/ '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
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]
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
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. 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'
      { $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 :: Lens' PutFunctionConcurrency Text
putFunctionConcurrency_functionName = 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 :: Lens' PutFunctionConcurrency Natural
putFunctionConcurrency_reservedConcurrentExecutions = 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 :: (Service -> Service)
-> PutFunctionConcurrency -> Request PutFunctionConcurrency
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutFunctionConcurrency
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutFunctionConcurrency)))
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 PutFunctionConcurrency where
  hashWithSalt :: Int -> PutFunctionConcurrency -> Int
hashWithSalt Int
_salt PutFunctionConcurrency' {Natural
Text
reservedConcurrentExecutions :: Natural
functionName :: Text
$sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: PutFunctionConcurrency -> Natural
$sel:functionName:PutFunctionConcurrency' :: PutFunctionConcurrency -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
functionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
reservedConcurrentExecutions

instance Prelude.NFData PutFunctionConcurrency where
  rnf :: PutFunctionConcurrency -> ()
rnf PutFunctionConcurrency' {Natural
Text
reservedConcurrentExecutions :: Natural
functionName :: Text
$sel:reservedConcurrentExecutions:PutFunctionConcurrency' :: PutFunctionConcurrency -> Natural
$sel:functionName:PutFunctionConcurrency' :: PutFunctionConcurrency -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
functionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
reservedConcurrentExecutions

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              ( Key
"ReservedConcurrentExecutions"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
reservedConcurrentExecutions
              )
          ]
      )

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

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