{-# 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.Invoke
-- 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)
--
-- Invokes a Lambda function. You can invoke a function synchronously (and
-- wait for the response), or asynchronously. To invoke a function
-- asynchronously, set @InvocationType@ to @Event@.
--
-- For
-- <https://docs.aws.amazon.com/lambda/latest/dg/invocation-sync.html synchronous invocation>,
-- details about the function response, including errors, are included in
-- the response body and headers. For either invocation type, you can find
-- more information in the
-- <https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions.html execution log>
-- and
-- <https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html trace>.
--
-- When an error occurs, your function may be invoked multiple times. Retry
-- behavior varies by error type, client, event source, and invocation
-- type. For example, if you invoke a function asynchronously and it
-- returns an error, Lambda executes the function up to two more times. For
-- more information, see
-- <https://docs.aws.amazon.com/lambda/latest/dg/retries-on-errors.html Retry Behavior>.
--
-- For
-- <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html asynchronous invocation>,
-- Lambda adds events to a queue before sending them to your function. If
-- your function does not have enough capacity to keep up with the queue,
-- events may be lost. Occasionally, your function may receive the same
-- event multiple times, even if no error occurs. To retain events that
-- were not processed, configure your function with a
-- <https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#dlq dead-letter queue>.
--
-- The status code in the API response doesn\'t reflect function errors.
-- Error codes are reserved for errors that prevent your function from
-- executing, such as permissions errors,
-- <https://docs.aws.amazon.com/lambda/latest/dg/limits.html limit errors>,
-- or issues with your function\'s code and configuration. For example,
-- Lambda returns @TooManyRequestsException@ if executing the function
-- would cause you to exceed a concurrency limit at either the account
-- level (@ConcurrentInvocationLimitExceeded@) or function level
-- (@ReservedFunctionConcurrentInvocationLimitExceeded@).
--
-- For functions with a long timeout, your client might be disconnected
-- during synchronous invocation while it waits for a response. Configure
-- your HTTP client, SDK, firewall, proxy, or operating system to allow for
-- long connections with timeout or keep-alive settings.
--
-- This operation requires permission for the
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awslambda.html lambda:InvokeFunction>
-- action.
module Amazonka.Lambda.Invoke
  ( -- * Creating a Request
    Invoke (..),
    newInvoke,

    -- * Request Lenses
    invoke_invocationType,
    invoke_logType,
    invoke_qualifier,
    invoke_clientContext,
    invoke_functionName,
    invoke_payload,

    -- * Destructuring the Response
    InvokeResponse (..),
    newInvokeResponse,

    -- * Response Lenses
    invokeResponse_functionError,
    invokeResponse_logResult,
    invokeResponse_payload,
    invokeResponse_executedVersion,
    invokeResponse_statusCode,
  )
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:/ 'newInvoke' smart constructor.
data Invoke = Invoke'
  { -- | Choose from the following options.
    --
    -- -   @RequestResponse@ (default) - Invoke the function synchronously.
    --     Keep the connection open until the function returns a response or
    --     times out. The API response includes the function response and
    --     additional data.
    --
    -- -   @Event@ - Invoke the function asynchronously. Send events that fail
    --     multiple times to the function\'s dead-letter queue (if it\'s
    --     configured). The API response only includes a status code.
    --
    -- -   @DryRun@ - Validate parameter values and verify that the user or
    --     role has permission to invoke the function.
    Invoke -> Maybe InvocationType
invocationType :: Prelude.Maybe InvocationType,
    -- | Set to @Tail@ to include the execution log in the response. Applies to
    -- synchronously invoked functions only.
    Invoke -> Maybe LogType
logType :: Prelude.Maybe LogType,
    -- | Specify a version or alias to invoke a published version of the
    -- function.
    Invoke -> Maybe Text
qualifier :: Prelude.Maybe Prelude.Text,
    -- | Up to 3583 bytes of base64-encoded data about the invoking client to
    -- pass to the function in the context object.
    Invoke -> Maybe Text
clientContext :: Prelude.Maybe Prelude.Text,
    -- | The name of the Lambda function, version, or alias.
    --
    -- __Name formats__
    --
    -- -   __Function name__ - @my-function@ (name-only), @my-function:v1@
    --     (with alias).
    --
    -- -   __Function ARN__ -
    --     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
    --
    -- -   __Partial ARN__ - @123456789012:function:my-function@.
    --
    -- You can append a version number or alias to any of the formats. The
    -- length constraint applies only to the full ARN. If you specify only the
    -- function name, it is limited to 64 characters in length.
    Invoke -> Text
functionName :: Prelude.Text,
    -- | The JSON that you want to provide to your Lambda function as input.
    Invoke -> ByteString
payload :: Prelude.ByteString
  }
  deriving (Invoke -> Invoke -> Bool
(Invoke -> Invoke -> Bool)
-> (Invoke -> Invoke -> Bool) -> Eq Invoke
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Invoke -> Invoke -> Bool
$c/= :: Invoke -> Invoke -> Bool
== :: Invoke -> Invoke -> Bool
$c== :: Invoke -> Invoke -> Bool
Prelude.Eq, Int -> Invoke -> ShowS
[Invoke] -> ShowS
Invoke -> String
(Int -> Invoke -> ShowS)
-> (Invoke -> String) -> ([Invoke] -> ShowS) -> Show Invoke
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Invoke] -> ShowS
$cshowList :: [Invoke] -> ShowS
show :: Invoke -> String
$cshow :: Invoke -> String
showsPrec :: Int -> Invoke -> ShowS
$cshowsPrec :: Int -> Invoke -> ShowS
Prelude.Show, (forall x. Invoke -> Rep Invoke x)
-> (forall x. Rep Invoke x -> Invoke) -> Generic Invoke
forall x. Rep Invoke x -> Invoke
forall x. Invoke -> Rep Invoke x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Invoke x -> Invoke
$cfrom :: forall x. Invoke -> Rep Invoke x
Prelude.Generic)

-- |
-- Create a value of 'Invoke' 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:
--
-- 'invocationType', 'invoke_invocationType' - Choose from the following options.
--
-- -   @RequestResponse@ (default) - Invoke the function synchronously.
--     Keep the connection open until the function returns a response or
--     times out. The API response includes the function response and
--     additional data.
--
-- -   @Event@ - Invoke the function asynchronously. Send events that fail
--     multiple times to the function\'s dead-letter queue (if it\'s
--     configured). The API response only includes a status code.
--
-- -   @DryRun@ - Validate parameter values and verify that the user or
--     role has permission to invoke the function.
--
-- 'logType', 'invoke_logType' - Set to @Tail@ to include the execution log in the response. Applies to
-- synchronously invoked functions only.
--
-- 'qualifier', 'invoke_qualifier' - Specify a version or alias to invoke a published version of the
-- function.
--
-- 'clientContext', 'invoke_clientContext' - Up to 3583 bytes of base64-encoded data about the invoking client to
-- pass to the function in the context object.
--
-- 'functionName', 'invoke_functionName' - The name of the Lambda function, version, or alias.
--
-- __Name formats__
--
-- -   __Function name__ - @my-function@ (name-only), @my-function:v1@
--     (with alias).
--
-- -   __Function ARN__ -
--     @arn:aws:lambda:us-west-2:123456789012:function:my-function@.
--
-- -   __Partial ARN__ - @123456789012:function:my-function@.
--
-- You can append a version number or alias to any of the formats. The
-- length constraint applies only to the full ARN. If you specify only the
-- function name, it is limited to 64 characters in length.
--
-- 'payload', 'invoke_payload' - The JSON that you want to provide to your Lambda function as input.
newInvoke ::
  -- | 'functionName'
  Prelude.Text ->
  -- | 'payload'
  Prelude.ByteString ->
  Invoke
newInvoke :: Text -> ByteString -> Invoke
newInvoke Text
pFunctionName_ ByteString
pPayload_ =
  Invoke' :: Maybe InvocationType
-> Maybe LogType
-> Maybe Text
-> Maybe Text
-> Text
-> ByteString
-> Invoke
Invoke'
    { $sel:invocationType:Invoke' :: Maybe InvocationType
invocationType = Maybe InvocationType
forall a. Maybe a
Prelude.Nothing,
      $sel:logType:Invoke' :: Maybe LogType
logType = Maybe LogType
forall a. Maybe a
Prelude.Nothing,
      $sel:qualifier:Invoke' :: Maybe Text
qualifier = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:clientContext:Invoke' :: Maybe Text
clientContext = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:functionName:Invoke' :: Text
functionName = Text
pFunctionName_,
      $sel:payload:Invoke' :: ByteString
payload = ByteString
pPayload_
    }

-- | Choose from the following options.
--
-- -   @RequestResponse@ (default) - Invoke the function synchronously.
--     Keep the connection open until the function returns a response or
--     times out. The API response includes the function response and
--     additional data.
--
-- -   @Event@ - Invoke the function asynchronously. Send events that fail
--     multiple times to the function\'s dead-letter queue (if it\'s
--     configured). The API response only includes a status code.
--
-- -   @DryRun@ - Validate parameter values and verify that the user or
--     role has permission to invoke the function.
invoke_invocationType :: Lens.Lens' Invoke (Prelude.Maybe InvocationType)
invoke_invocationType :: (Maybe InvocationType -> f (Maybe InvocationType))
-> Invoke -> f Invoke
invoke_invocationType = (Invoke -> Maybe InvocationType)
-> (Invoke -> Maybe InvocationType -> Invoke)
-> Lens Invoke Invoke (Maybe InvocationType) (Maybe InvocationType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Invoke' {Maybe InvocationType
invocationType :: Maybe InvocationType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
invocationType} -> Maybe InvocationType
invocationType) (\s :: Invoke
s@Invoke' {} Maybe InvocationType
a -> Invoke
s {$sel:invocationType:Invoke' :: Maybe InvocationType
invocationType = Maybe InvocationType
a} :: Invoke)

-- | Set to @Tail@ to include the execution log in the response. Applies to
-- synchronously invoked functions only.
invoke_logType :: Lens.Lens' Invoke (Prelude.Maybe LogType)
invoke_logType :: (Maybe LogType -> f (Maybe LogType)) -> Invoke -> f Invoke
invoke_logType = (Invoke -> Maybe LogType)
-> (Invoke -> Maybe LogType -> Invoke)
-> Lens Invoke Invoke (Maybe LogType) (Maybe LogType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Invoke' {Maybe LogType
logType :: Maybe LogType
$sel:logType:Invoke' :: Invoke -> Maybe LogType
logType} -> Maybe LogType
logType) (\s :: Invoke
s@Invoke' {} Maybe LogType
a -> Invoke
s {$sel:logType:Invoke' :: Maybe LogType
logType = Maybe LogType
a} :: Invoke)

-- | Specify a version or alias to invoke a published version of the
-- function.
invoke_qualifier :: Lens.Lens' Invoke (Prelude.Maybe Prelude.Text)
invoke_qualifier :: (Maybe Text -> f (Maybe Text)) -> Invoke -> f Invoke
invoke_qualifier = (Invoke -> Maybe Text)
-> (Invoke -> Maybe Text -> Invoke)
-> Lens Invoke Invoke (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Invoke' {Maybe Text
qualifier :: Maybe Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
qualifier} -> Maybe Text
qualifier) (\s :: Invoke
s@Invoke' {} Maybe Text
a -> Invoke
s {$sel:qualifier:Invoke' :: Maybe Text
qualifier = Maybe Text
a} :: Invoke)

-- | Up to 3583 bytes of base64-encoded data about the invoking client to
-- pass to the function in the context object.
invoke_clientContext :: Lens.Lens' Invoke (Prelude.Maybe Prelude.Text)
invoke_clientContext :: (Maybe Text -> f (Maybe Text)) -> Invoke -> f Invoke
invoke_clientContext = (Invoke -> Maybe Text)
-> (Invoke -> Maybe Text -> Invoke)
-> Lens Invoke Invoke (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Invoke' {Maybe Text
clientContext :: Maybe Text
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
clientContext} -> Maybe Text
clientContext) (\s :: Invoke
s@Invoke' {} Maybe Text
a -> Invoke
s {$sel:clientContext:Invoke' :: Maybe Text
clientContext = Maybe Text
a} :: Invoke)

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

-- | The JSON that you want to provide to your Lambda function as input.
invoke_payload :: Lens.Lens' Invoke Prelude.ByteString
invoke_payload :: (ByteString -> f ByteString) -> Invoke -> f Invoke
invoke_payload = (Invoke -> ByteString)
-> (Invoke -> ByteString -> Invoke)
-> Lens Invoke Invoke ByteString ByteString
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Invoke' {ByteString
payload :: ByteString
$sel:payload:Invoke' :: Invoke -> ByteString
payload} -> ByteString
payload) (\s :: Invoke
s@Invoke' {} ByteString
a -> Invoke
s {$sel:payload:Invoke' :: ByteString
payload = ByteString
a} :: Invoke)

instance Core.AWSRequest Invoke where
  type AWSResponse Invoke = InvokeResponse
  request :: Invoke -> Request Invoke
request = Service -> Invoke -> Request Invoke
forall a. (ToRequest a, ToBody a) => Service -> a -> Request a
Request.postBody Service
defaultService
  response :: Logger
-> Service
-> Proxy Invoke
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Invoke)))
response =
    (Int
 -> ResponseHeaders
 -> ByteString
 -> Either String (AWSResponse Invoke))
-> Logger
-> Service
-> Proxy Invoke
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Invoke)))
forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders -> ByteString -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBytes
      ( \Int
s ResponseHeaders
h ByteString
x ->
          Maybe Text
-> Maybe Text
-> Maybe ByteString
-> Maybe Text
-> Int
-> InvokeResponse
InvokeResponse'
            (Maybe Text
 -> Maybe Text
 -> Maybe ByteString
 -> Maybe Text
 -> Int
 -> InvokeResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe ByteString -> Maybe Text -> Int -> InvokeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"X-Amz-Function-Error")
            Either
  String
  (Maybe Text
   -> Maybe ByteString -> Maybe Text -> Int -> InvokeResponse)
-> Either String (Maybe Text)
-> Either
     String (Maybe ByteString -> Maybe Text -> Int -> InvokeResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"X-Amz-Log-Result")
            Either
  String (Maybe ByteString -> Maybe Text -> Int -> InvokeResponse)
-> Either String (Maybe ByteString)
-> Either String (Maybe Text -> Int -> InvokeResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Maybe ByteString -> Either String (Maybe ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Prelude.Just (ByteString -> ByteString
Prelude.coerce ByteString
x)))
            Either String (Maybe Text -> Int -> InvokeResponse)
-> Either String (Maybe Text)
-> Either String (Int -> InvokeResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h ResponseHeaders -> HeaderName -> Either String (Maybe Text)
forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Core..#? HeaderName
"X-Amz-Executed-Version")
            Either String (Int -> InvokeResponse)
-> Either String Int -> Either String InvokeResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable Invoke

instance Prelude.NFData Invoke

instance Core.ToBody Invoke where
  toBody :: Invoke -> RequestBody
toBody Invoke' {Maybe Text
Maybe InvocationType
Maybe LogType
ByteString
Text
payload :: ByteString
functionName :: Text
clientContext :: Maybe Text
qualifier :: Maybe Text
logType :: Maybe LogType
invocationType :: Maybe InvocationType
$sel:payload:Invoke' :: Invoke -> ByteString
$sel:functionName:Invoke' :: Invoke -> Text
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
$sel:logType:Invoke' :: Invoke -> Maybe LogType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
..} = ByteString -> RequestBody
forall a. ToBody a => a -> RequestBody
Core.toBody ByteString
payload

instance Core.ToHeaders Invoke where
  toHeaders :: Invoke -> ResponseHeaders
toHeaders Invoke' {Maybe Text
Maybe InvocationType
Maybe LogType
ByteString
Text
payload :: ByteString
functionName :: Text
clientContext :: Maybe Text
qualifier :: Maybe Text
logType :: Maybe LogType
invocationType :: Maybe InvocationType
$sel:payload:Invoke' :: Invoke -> ByteString
$sel:functionName:Invoke' :: Invoke -> Text
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
$sel:logType:Invoke' :: Invoke -> Maybe LogType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"X-Amz-Invocation-Type" HeaderName -> Maybe InvocationType -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe InvocationType
invocationType,
        HeaderName
"X-Amz-Log-Type" HeaderName -> Maybe LogType -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe LogType
logType,
        HeaderName
"X-Amz-Client-Context" HeaderName -> Maybe Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Maybe Text
clientContext
      ]

instance Core.ToPath Invoke where
  toPath :: Invoke -> ByteString
toPath Invoke' {Maybe Text
Maybe InvocationType
Maybe LogType
ByteString
Text
payload :: ByteString
functionName :: Text
clientContext :: Maybe Text
qualifier :: Maybe Text
logType :: Maybe LogType
invocationType :: Maybe InvocationType
$sel:payload:Invoke' :: Invoke -> ByteString
$sel:functionName:Invoke' :: Invoke -> Text
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
$sel:logType:Invoke' :: Invoke -> Maybe LogType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
..} =
    [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
"/invocations"
      ]

instance Core.ToQuery Invoke where
  toQuery :: Invoke -> QueryString
toQuery Invoke' {Maybe Text
Maybe InvocationType
Maybe LogType
ByteString
Text
payload :: ByteString
functionName :: Text
clientContext :: Maybe Text
qualifier :: Maybe Text
logType :: Maybe LogType
invocationType :: Maybe InvocationType
$sel:payload:Invoke' :: Invoke -> ByteString
$sel:functionName:Invoke' :: Invoke -> Text
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
$sel:logType:Invoke' :: Invoke -> Maybe LogType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"Qualifier" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
qualifier]

-- | /See:/ 'newInvokeResponse' smart constructor.
data InvokeResponse = InvokeResponse'
  { -- | If present, indicates that an error occurred during function execution.
    -- Details about the error are included in the response payload.
    InvokeResponse -> Maybe Text
functionError :: Prelude.Maybe Prelude.Text,
    -- | The last 4 KB of the execution log, which is base64 encoded.
    InvokeResponse -> Maybe Text
logResult :: Prelude.Maybe Prelude.Text,
    -- | The response from the function, or an error object.
    InvokeResponse -> Maybe ByteString
payload :: Prelude.Maybe Prelude.ByteString,
    -- | The version of the function that executed. When you invoke a function
    -- with an alias, this indicates which version the alias resolved to.
    InvokeResponse -> Maybe Text
executedVersion :: Prelude.Maybe Prelude.Text,
    -- | The HTTP status code is in the 200 range for a successful request. For
    -- the @RequestResponse@ invocation type, this status code is 200. For the
    -- @Event@ invocation type, this status code is 202. For the @DryRun@
    -- invocation type, the status code is 204.
    InvokeResponse -> Int
statusCode :: Prelude.Int
  }
  deriving (InvokeResponse -> InvokeResponse -> Bool
(InvokeResponse -> InvokeResponse -> Bool)
-> (InvokeResponse -> InvokeResponse -> Bool) -> Eq InvokeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InvokeResponse -> InvokeResponse -> Bool
$c/= :: InvokeResponse -> InvokeResponse -> Bool
== :: InvokeResponse -> InvokeResponse -> Bool
$c== :: InvokeResponse -> InvokeResponse -> Bool
Prelude.Eq, Int -> InvokeResponse -> ShowS
[InvokeResponse] -> ShowS
InvokeResponse -> String
(Int -> InvokeResponse -> ShowS)
-> (InvokeResponse -> String)
-> ([InvokeResponse] -> ShowS)
-> Show InvokeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InvokeResponse] -> ShowS
$cshowList :: [InvokeResponse] -> ShowS
show :: InvokeResponse -> String
$cshow :: InvokeResponse -> String
showsPrec :: Int -> InvokeResponse -> ShowS
$cshowsPrec :: Int -> InvokeResponse -> ShowS
Prelude.Show, (forall x. InvokeResponse -> Rep InvokeResponse x)
-> (forall x. Rep InvokeResponse x -> InvokeResponse)
-> Generic InvokeResponse
forall x. Rep InvokeResponse x -> InvokeResponse
forall x. InvokeResponse -> Rep InvokeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InvokeResponse x -> InvokeResponse
$cfrom :: forall x. InvokeResponse -> Rep InvokeResponse x
Prelude.Generic)

-- |
-- Create a value of 'InvokeResponse' 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:
--
-- 'functionError', 'invokeResponse_functionError' - If present, indicates that an error occurred during function execution.
-- Details about the error are included in the response payload.
--
-- 'logResult', 'invokeResponse_logResult' - The last 4 KB of the execution log, which is base64 encoded.
--
-- 'payload', 'invokeResponse_payload' - The response from the function, or an error object.
--
-- 'executedVersion', 'invokeResponse_executedVersion' - The version of the function that executed. When you invoke a function
-- with an alias, this indicates which version the alias resolved to.
--
-- 'statusCode', 'invokeResponse_statusCode' - The HTTP status code is in the 200 range for a successful request. For
-- the @RequestResponse@ invocation type, this status code is 200. For the
-- @Event@ invocation type, this status code is 202. For the @DryRun@
-- invocation type, the status code is 204.
newInvokeResponse ::
  -- | 'statusCode'
  Prelude.Int ->
  InvokeResponse
newInvokeResponse :: Int -> InvokeResponse
newInvokeResponse Int
pStatusCode_ =
  InvokeResponse' :: Maybe Text
-> Maybe Text
-> Maybe ByteString
-> Maybe Text
-> Int
-> InvokeResponse
InvokeResponse'
    { $sel:functionError:InvokeResponse' :: Maybe Text
functionError = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:logResult:InvokeResponse' :: Maybe Text
logResult = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:payload:InvokeResponse' :: Maybe ByteString
payload = Maybe ByteString
forall a. Maybe a
Prelude.Nothing,
      $sel:executedVersion:InvokeResponse' :: Maybe Text
executedVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:InvokeResponse' :: Int
statusCode = Int
pStatusCode_
    }

-- | If present, indicates that an error occurred during function execution.
-- Details about the error are included in the response payload.
invokeResponse_functionError :: Lens.Lens' InvokeResponse (Prelude.Maybe Prelude.Text)
invokeResponse_functionError :: (Maybe Text -> f (Maybe Text))
-> InvokeResponse -> f InvokeResponse
invokeResponse_functionError = (InvokeResponse -> Maybe Text)
-> (InvokeResponse -> Maybe Text -> InvokeResponse)
-> Lens InvokeResponse InvokeResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvokeResponse' {Maybe Text
functionError :: Maybe Text
$sel:functionError:InvokeResponse' :: InvokeResponse -> Maybe Text
functionError} -> Maybe Text
functionError) (\s :: InvokeResponse
s@InvokeResponse' {} Maybe Text
a -> InvokeResponse
s {$sel:functionError:InvokeResponse' :: Maybe Text
functionError = Maybe Text
a} :: InvokeResponse)

-- | The last 4 KB of the execution log, which is base64 encoded.
invokeResponse_logResult :: Lens.Lens' InvokeResponse (Prelude.Maybe Prelude.Text)
invokeResponse_logResult :: (Maybe Text -> f (Maybe Text))
-> InvokeResponse -> f InvokeResponse
invokeResponse_logResult = (InvokeResponse -> Maybe Text)
-> (InvokeResponse -> Maybe Text -> InvokeResponse)
-> Lens InvokeResponse InvokeResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvokeResponse' {Maybe Text
logResult :: Maybe Text
$sel:logResult:InvokeResponse' :: InvokeResponse -> Maybe Text
logResult} -> Maybe Text
logResult) (\s :: InvokeResponse
s@InvokeResponse' {} Maybe Text
a -> InvokeResponse
s {$sel:logResult:InvokeResponse' :: Maybe Text
logResult = Maybe Text
a} :: InvokeResponse)

-- | The response from the function, or an error object.
invokeResponse_payload :: Lens.Lens' InvokeResponse (Prelude.Maybe Prelude.ByteString)
invokeResponse_payload :: (Maybe ByteString -> f (Maybe ByteString))
-> InvokeResponse -> f InvokeResponse
invokeResponse_payload = (InvokeResponse -> Maybe ByteString)
-> (InvokeResponse -> Maybe ByteString -> InvokeResponse)
-> Lens
     InvokeResponse InvokeResponse (Maybe ByteString) (Maybe ByteString)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvokeResponse' {Maybe ByteString
payload :: Maybe ByteString
$sel:payload:InvokeResponse' :: InvokeResponse -> Maybe ByteString
payload} -> Maybe ByteString
payload) (\s :: InvokeResponse
s@InvokeResponse' {} Maybe ByteString
a -> InvokeResponse
s {$sel:payload:InvokeResponse' :: Maybe ByteString
payload = Maybe ByteString
a} :: InvokeResponse)

-- | The version of the function that executed. When you invoke a function
-- with an alias, this indicates which version the alias resolved to.
invokeResponse_executedVersion :: Lens.Lens' InvokeResponse (Prelude.Maybe Prelude.Text)
invokeResponse_executedVersion :: (Maybe Text -> f (Maybe Text))
-> InvokeResponse -> f InvokeResponse
invokeResponse_executedVersion = (InvokeResponse -> Maybe Text)
-> (InvokeResponse -> Maybe Text -> InvokeResponse)
-> Lens InvokeResponse InvokeResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvokeResponse' {Maybe Text
executedVersion :: Maybe Text
$sel:executedVersion:InvokeResponse' :: InvokeResponse -> Maybe Text
executedVersion} -> Maybe Text
executedVersion) (\s :: InvokeResponse
s@InvokeResponse' {} Maybe Text
a -> InvokeResponse
s {$sel:executedVersion:InvokeResponse' :: Maybe Text
executedVersion = Maybe Text
a} :: InvokeResponse)

-- | The HTTP status code is in the 200 range for a successful request. For
-- the @RequestResponse@ invocation type, this status code is 200. For the
-- @Event@ invocation type, this status code is 202. For the @DryRun@
-- invocation type, the status code is 204.
invokeResponse_statusCode :: Lens.Lens' InvokeResponse Prelude.Int
invokeResponse_statusCode :: (Int -> f Int) -> InvokeResponse -> f InvokeResponse
invokeResponse_statusCode = (InvokeResponse -> Int)
-> (InvokeResponse -> Int -> InvokeResponse)
-> Lens InvokeResponse InvokeResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InvokeResponse' {Int
statusCode :: Int
$sel:statusCode:InvokeResponse' :: InvokeResponse -> Int
statusCode} -> Int
statusCode) (\s :: InvokeResponse
s@InvokeResponse' {} Int
a -> InvokeResponse
s {$sel:statusCode:InvokeResponse' :: Int
statusCode = Int
a} :: InvokeResponse)

instance Prelude.NFData InvokeResponse