{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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/invocation-retries.html Error handling and automatic retries in Lambda>.
--
-- 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#invocation-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/gettingstarted-limits.html quota>
-- errors, or issues with your function\'s code and configuration. For
-- example, Lambda returns @TooManyRequestsException@ if running 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 disconnect 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. For details on how to set up permissions for cross-account
-- invocations, see
-- <https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html#permissions-resource-xaccountinvoke Granting function access to other accounts>.
module Amazonka.Lambda.Invoke
  ( -- * Creating a Request
    Invoke (..),
    newInvoke,

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

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

    -- * Response Lenses
    invokeResponse_executedVersion,
    invokeResponse_functionError,
    invokeResponse_logResult,
    invokeResponse_payload,
    invokeResponse_statusCode,
  )
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:/ 'newInvoke' smart constructor.
data Invoke = Invoke'
  { -- | Up to 3,583 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,
    -- | 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 one is
    --     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,
    -- | 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.
    --
    -- You can enter the JSON directly. For example,
    -- @--payload \'{ \"key\": \"value\" }\'@. You can also specify a file
    -- path. For example, @--payload file:\/\/payload.json@.
    Invoke -> ByteString
payload :: Prelude.ByteString
  }
  deriving (Invoke -> Invoke -> Bool
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
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. 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:
--
-- 'clientContext', 'invoke_clientContext' - Up to 3,583 bytes of base64-encoded data about the invoking client to
-- pass to the function in the context object.
--
-- '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 one is
--     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.
--
-- '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.
--
-- You can enter the JSON directly. For example,
-- @--payload \'{ \"key\": \"value\" }\'@. You can also specify a file
-- path. For example, @--payload file:\/\/payload.json@.
newInvoke ::
  -- | 'functionName'
  Prelude.Text ->
  -- | 'payload'
  Prelude.ByteString ->
  Invoke
newInvoke :: Text -> ByteString -> Invoke
newInvoke Text
pFunctionName_ ByteString
pPayload_ =
  Invoke'
    { $sel:clientContext:Invoke' :: Maybe Text
clientContext = forall a. Maybe a
Prelude.Nothing,
      $sel:invocationType:Invoke' :: Maybe InvocationType
invocationType = forall a. Maybe a
Prelude.Nothing,
      $sel:logType:Invoke' :: Maybe LogType
logType = forall a. Maybe a
Prelude.Nothing,
      $sel:qualifier:Invoke' :: Maybe Text
qualifier = forall a. Maybe a
Prelude.Nothing,
      $sel:functionName:Invoke' :: Text
functionName = Text
pFunctionName_,
      $sel:payload:Invoke' :: ByteString
payload = ByteString
pPayload_
    }

-- | Up to 3,583 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 :: Lens' Invoke (Maybe Text)
invoke_clientContext = 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)

-- | 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 one is
--     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 :: Lens' Invoke (Maybe InvocationType)
invoke_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 :: Lens' Invoke (Maybe LogType)
invoke_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 :: Lens' Invoke (Maybe Text)
invoke_qualifier = 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)

-- | 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 :: Lens' Invoke Text
invoke_functionName = 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.
--
-- You can enter the JSON directly. For example,
-- @--payload \'{ \"key\": \"value\" }\'@. You can also specify a file
-- path. For example, @--payload file:\/\/payload.json@.
invoke_payload :: Lens.Lens' Invoke Prelude.ByteString
invoke_payload :: Lens' Invoke ByteString
invoke_payload = 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 :: (Service -> Service) -> Invoke -> Request Invoke
request Service -> Service
overrides =
    forall a. (ToRequest a, ToBody a) => Service -> a -> Request a
Request.postBody (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy Invoke
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse Invoke)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int
 -> ResponseHeaders -> ByteString -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveBytes
      ( \Int
s ResponseHeaders
h ByteString
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe ByteString
-> Int
-> InvokeResponse
InvokeResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Data..#? HeaderName
"X-Amz-Executed-Version")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Data..#? HeaderName
"X-Amz-Function-Error")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (ResponseHeaders
h forall a.
FromText a =>
ResponseHeaders -> HeaderName -> Either String (Maybe a)
Data..#? HeaderName
"X-Amz-Log-Result")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. a -> Maybe a
Prelude.Just (coerce :: forall a b. Coercible a b => a -> b
Prelude.coerce ByteString
x)))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable Invoke where
  hashWithSalt :: Int -> Invoke -> Int
hashWithSalt Int
_salt Invoke' {Maybe Text
Maybe InvocationType
Maybe LogType
ByteString
Text
payload :: ByteString
functionName :: Text
qualifier :: Maybe Text
logType :: Maybe LogType
invocationType :: Maybe InvocationType
clientContext :: Maybe Text
$sel:payload:Invoke' :: Invoke -> ByteString
$sel:functionName:Invoke' :: Invoke -> Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
$sel:logType:Invoke' :: Invoke -> Maybe LogType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientContext
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe InvocationType
invocationType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LogType
logType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
qualifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
functionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ByteString
payload

instance Prelude.NFData Invoke where
  rnf :: Invoke -> ()
rnf Invoke' {Maybe Text
Maybe InvocationType
Maybe LogType
ByteString
Text
payload :: ByteString
functionName :: Text
qualifier :: Maybe Text
logType :: Maybe LogType
invocationType :: Maybe InvocationType
clientContext :: Maybe Text
$sel:payload:Invoke' :: Invoke -> ByteString
$sel:functionName:Invoke' :: Invoke -> Text
$sel:qualifier:Invoke' :: Invoke -> Maybe Text
$sel:logType:Invoke' :: Invoke -> Maybe LogType
$sel:invocationType:Invoke' :: Invoke -> Maybe InvocationType
$sel:clientContext:Invoke' :: Invoke -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientContext
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe InvocationType
invocationType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe LogType
logType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
qualifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 ByteString
payload

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

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

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

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

-- | /See:/ 'newInvokeResponse' smart constructor.
data InvokeResponse = 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 -> Maybe Text
executedVersion :: Prelude.Maybe Prelude.Text,
    -- | 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 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
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
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. 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:
--
-- '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.
--
-- '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.
--
-- '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'
    { $sel:executedVersion:InvokeResponse' :: Maybe Text
executedVersion = forall a. Maybe a
Prelude.Nothing,
      $sel:functionError:InvokeResponse' :: Maybe Text
functionError = forall a. Maybe a
Prelude.Nothing,
      $sel:logResult:InvokeResponse' :: Maybe Text
logResult = forall a. Maybe a
Prelude.Nothing,
      $sel:payload:InvokeResponse' :: Maybe ByteString
payload = forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:InvokeResponse' :: Int
statusCode = Int
pStatusCode_
    }

-- | 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 :: Lens' InvokeResponse (Maybe Text)
invokeResponse_executedVersion = 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)

-- | 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 :: Lens' InvokeResponse (Maybe Text)
invokeResponse_functionError = 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 :: Lens' InvokeResponse (Maybe Text)
invokeResponse_logResult = 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 :: Lens' InvokeResponse (Maybe ByteString)
invokeResponse_payload = 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 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 :: Lens' InvokeResponse Int
invokeResponse_statusCode = 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 where
  rnf :: InvokeResponse -> ()
rnf InvokeResponse' {Int
Maybe ByteString
Maybe Text
statusCode :: Int
payload :: Maybe ByteString
logResult :: Maybe Text
functionError :: Maybe Text
executedVersion :: Maybe Text
$sel:statusCode:InvokeResponse' :: InvokeResponse -> Int
$sel:payload:InvokeResponse' :: InvokeResponse -> Maybe ByteString
$sel:logResult:InvokeResponse' :: InvokeResponse -> Maybe Text
$sel:functionError:InvokeResponse' :: InvokeResponse -> Maybe Text
$sel:executedVersion:InvokeResponse' :: InvokeResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
executedVersion
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
functionError
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
logResult
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ByteString
payload
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
statusCode