{-# 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.CloudWatchLogs.CreateLogStream
-- 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 log stream for the specified log group. A log stream is a
-- sequence of log events that originate from a single source, such as an
-- application instance or a resource that is being monitored.
--
-- There is no limit on the number of log streams that you can create for a
-- log group. There is a limit of 50 TPS on @CreateLogStream@ operations,
-- after which transactions are throttled.
--
-- You must use the following guidelines when naming a log stream:
--
-- -   Log stream names must be unique within the log group.
--
-- -   Log stream names can be between 1 and 512 characters long.
--
-- -   Don\'t use \':\' (colon) or \'*\' (asterisk) characters.
module Amazonka.CloudWatchLogs.CreateLogStream
  ( -- * Creating a Request
    CreateLogStream (..),
    newCreateLogStream,

    -- * Request Lenses
    createLogStream_logGroupName,
    createLogStream_logStreamName,

    -- * Destructuring the Response
    CreateLogStreamResponse (..),
    newCreateLogStreamResponse,
  )
where

import Amazonka.CloudWatchLogs.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newCreateLogStream' smart constructor.
data CreateLogStream = CreateLogStream'
  { -- | The name of the log group.
    CreateLogStream -> Text
logGroupName :: Prelude.Text,
    -- | The name of the log stream.
    CreateLogStream -> Text
logStreamName :: Prelude.Text
  }
  deriving (CreateLogStream -> CreateLogStream -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateLogStream -> CreateLogStream -> Bool
$c/= :: CreateLogStream -> CreateLogStream -> Bool
== :: CreateLogStream -> CreateLogStream -> Bool
$c== :: CreateLogStream -> CreateLogStream -> Bool
Prelude.Eq, ReadPrec [CreateLogStream]
ReadPrec CreateLogStream
Int -> ReadS CreateLogStream
ReadS [CreateLogStream]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateLogStream]
$creadListPrec :: ReadPrec [CreateLogStream]
readPrec :: ReadPrec CreateLogStream
$creadPrec :: ReadPrec CreateLogStream
readList :: ReadS [CreateLogStream]
$creadList :: ReadS [CreateLogStream]
readsPrec :: Int -> ReadS CreateLogStream
$creadsPrec :: Int -> ReadS CreateLogStream
Prelude.Read, Int -> CreateLogStream -> ShowS
[CreateLogStream] -> ShowS
CreateLogStream -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateLogStream] -> ShowS
$cshowList :: [CreateLogStream] -> ShowS
show :: CreateLogStream -> String
$cshow :: CreateLogStream -> String
showsPrec :: Int -> CreateLogStream -> ShowS
$cshowsPrec :: Int -> CreateLogStream -> ShowS
Prelude.Show, forall x. Rep CreateLogStream x -> CreateLogStream
forall x. CreateLogStream -> Rep CreateLogStream x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateLogStream x -> CreateLogStream
$cfrom :: forall x. CreateLogStream -> Rep CreateLogStream x
Prelude.Generic)

-- |
-- Create a value of 'CreateLogStream' 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:
--
-- 'logGroupName', 'createLogStream_logGroupName' - The name of the log group.
--
-- 'logStreamName', 'createLogStream_logStreamName' - The name of the log stream.
newCreateLogStream ::
  -- | 'logGroupName'
  Prelude.Text ->
  -- | 'logStreamName'
  Prelude.Text ->
  CreateLogStream
newCreateLogStream :: Text -> Text -> CreateLogStream
newCreateLogStream Text
pLogGroupName_ Text
pLogStreamName_ =
  CreateLogStream'
    { $sel:logGroupName:CreateLogStream' :: Text
logGroupName = Text
pLogGroupName_,
      $sel:logStreamName:CreateLogStream' :: Text
logStreamName = Text
pLogStreamName_
    }

-- | The name of the log group.
createLogStream_logGroupName :: Lens.Lens' CreateLogStream Prelude.Text
createLogStream_logGroupName :: Lens' CreateLogStream Text
createLogStream_logGroupName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLogStream' {Text
logGroupName :: Text
$sel:logGroupName:CreateLogStream' :: CreateLogStream -> Text
logGroupName} -> Text
logGroupName) (\s :: CreateLogStream
s@CreateLogStream' {} Text
a -> CreateLogStream
s {$sel:logGroupName:CreateLogStream' :: Text
logGroupName = Text
a} :: CreateLogStream)

-- | The name of the log stream.
createLogStream_logStreamName :: Lens.Lens' CreateLogStream Prelude.Text
createLogStream_logStreamName :: Lens' CreateLogStream Text
createLogStream_logStreamName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateLogStream' {Text
logStreamName :: Text
$sel:logStreamName:CreateLogStream' :: CreateLogStream -> Text
logStreamName} -> Text
logStreamName) (\s :: CreateLogStream
s@CreateLogStream' {} Text
a -> CreateLogStream
s {$sel:logStreamName:CreateLogStream' :: Text
logStreamName = Text
a} :: CreateLogStream)

instance Core.AWSRequest CreateLogStream where
  type
    AWSResponse CreateLogStream =
      CreateLogStreamResponse
  request :: (Service -> Service) -> CreateLogStream -> Request CreateLogStream
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 CreateLogStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateLogStream)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull CreateLogStreamResponse
CreateLogStreamResponse'

instance Prelude.Hashable CreateLogStream where
  hashWithSalt :: Int -> CreateLogStream -> Int
hashWithSalt Int
_salt CreateLogStream' {Text
logStreamName :: Text
logGroupName :: Text
$sel:logStreamName:CreateLogStream' :: CreateLogStream -> Text
$sel:logGroupName:CreateLogStream' :: CreateLogStream -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
logGroupName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
logStreamName

instance Prelude.NFData CreateLogStream where
  rnf :: CreateLogStream -> ()
rnf CreateLogStream' {Text
logStreamName :: Text
logGroupName :: Text
$sel:logStreamName:CreateLogStream' :: CreateLogStream -> Text
$sel:logGroupName:CreateLogStream' :: CreateLogStream -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
logGroupName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
logStreamName

instance Data.ToHeaders CreateLogStream where
  toHeaders :: CreateLogStream -> [Header]
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"Logs_20140328.CreateLogStream" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateLogStream where
  toJSON :: CreateLogStream -> Value
toJSON CreateLogStream' {Text
logStreamName :: Text
logGroupName :: Text
$sel:logStreamName:CreateLogStream' :: CreateLogStream -> Text
$sel:logGroupName:CreateLogStream' :: CreateLogStream -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"logGroupName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
logGroupName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"logStreamName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
logStreamName)
          ]
      )

instance Data.ToPath CreateLogStream where
  toPath :: CreateLogStream -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newCreateLogStreamResponse' smart constructor.
data CreateLogStreamResponse = CreateLogStreamResponse'
  {
  }
  deriving (CreateLogStreamResponse -> CreateLogStreamResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateLogStreamResponse -> CreateLogStreamResponse -> Bool
$c/= :: CreateLogStreamResponse -> CreateLogStreamResponse -> Bool
== :: CreateLogStreamResponse -> CreateLogStreamResponse -> Bool
$c== :: CreateLogStreamResponse -> CreateLogStreamResponse -> Bool
Prelude.Eq, ReadPrec [CreateLogStreamResponse]
ReadPrec CreateLogStreamResponse
Int -> ReadS CreateLogStreamResponse
ReadS [CreateLogStreamResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateLogStreamResponse]
$creadListPrec :: ReadPrec [CreateLogStreamResponse]
readPrec :: ReadPrec CreateLogStreamResponse
$creadPrec :: ReadPrec CreateLogStreamResponse
readList :: ReadS [CreateLogStreamResponse]
$creadList :: ReadS [CreateLogStreamResponse]
readsPrec :: Int -> ReadS CreateLogStreamResponse
$creadsPrec :: Int -> ReadS CreateLogStreamResponse
Prelude.Read, Int -> CreateLogStreamResponse -> ShowS
[CreateLogStreamResponse] -> ShowS
CreateLogStreamResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateLogStreamResponse] -> ShowS
$cshowList :: [CreateLogStreamResponse] -> ShowS
show :: CreateLogStreamResponse -> String
$cshow :: CreateLogStreamResponse -> String
showsPrec :: Int -> CreateLogStreamResponse -> ShowS
$cshowsPrec :: Int -> CreateLogStreamResponse -> ShowS
Prelude.Show, forall x. Rep CreateLogStreamResponse x -> CreateLogStreamResponse
forall x. CreateLogStreamResponse -> Rep CreateLogStreamResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateLogStreamResponse x -> CreateLogStreamResponse
$cfrom :: forall x. CreateLogStreamResponse -> Rep CreateLogStreamResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateLogStreamResponse' 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.
newCreateLogStreamResponse ::
  CreateLogStreamResponse
newCreateLogStreamResponse :: CreateLogStreamResponse
newCreateLogStreamResponse = CreateLogStreamResponse
CreateLogStreamResponse'

instance Prelude.NFData CreateLogStreamResponse where
  rnf :: CreateLogStreamResponse -> ()
rnf CreateLogStreamResponse
_ = ()