{-# 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-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)
--
-- 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.
--
-- -   The \':\' (colon) and \'*\' (asterisk) characters are not allowed.
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.Lens as Lens
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
(CreateLogStream -> CreateLogStream -> Bool)
-> (CreateLogStream -> CreateLogStream -> Bool)
-> Eq CreateLogStream
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]
(Int -> ReadS CreateLogStream)
-> ReadS [CreateLogStream]
-> ReadPrec CreateLogStream
-> ReadPrec [CreateLogStream]
-> Read 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
(Int -> CreateLogStream -> ShowS)
-> (CreateLogStream -> String)
-> ([CreateLogStream] -> ShowS)
-> Show CreateLogStream
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. CreateLogStream -> Rep CreateLogStream x)
-> (forall x. Rep CreateLogStream x -> CreateLogStream)
-> Generic CreateLogStream
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' :: Text -> Text -> CreateLogStream
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 :: (Text -> f Text) -> CreateLogStream -> f CreateLogStream
createLogStream_logGroupName = (CreateLogStream -> Text)
-> (CreateLogStream -> Text -> CreateLogStream)
-> Lens CreateLogStream CreateLogStream Text Text
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 :: (Text -> f Text) -> CreateLogStream -> f CreateLogStream
createLogStream_logStreamName = (CreateLogStream -> Text)
-> (CreateLogStream -> Text -> CreateLogStream)
-> Lens CreateLogStream CreateLogStream Text Text
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 :: CreateLogStream -> Request CreateLogStream
request = Service -> CreateLogStream -> Request CreateLogStream
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateLogStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateLogStream)))
response =
    AWSResponse CreateLogStream
-> Logger
-> Service
-> Proxy CreateLogStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateLogStream)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse CreateLogStream
CreateLogStreamResponse
CreateLogStreamResponse'

instance Prelude.Hashable CreateLogStream

instance Prelude.NFData CreateLogStream

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

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"logGroupName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logGroupName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"logStreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
logStreamName)
          ]
      )

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

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

-- | /See:/ 'newCreateLogStreamResponse' smart constructor.
data CreateLogStreamResponse = CreateLogStreamResponse'
  {
  }
  deriving (CreateLogStreamResponse -> CreateLogStreamResponse -> Bool
(CreateLogStreamResponse -> CreateLogStreamResponse -> Bool)
-> (CreateLogStreamResponse -> CreateLogStreamResponse -> Bool)
-> Eq CreateLogStreamResponse
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]
(Int -> ReadS CreateLogStreamResponse)
-> ReadS [CreateLogStreamResponse]
-> ReadPrec CreateLogStreamResponse
-> ReadPrec [CreateLogStreamResponse]
-> Read 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
(Int -> CreateLogStreamResponse -> ShowS)
-> (CreateLogStreamResponse -> String)
-> ([CreateLogStreamResponse] -> ShowS)
-> Show CreateLogStreamResponse
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.
 CreateLogStreamResponse -> Rep CreateLogStreamResponse x)
-> (forall x.
    Rep CreateLogStreamResponse x -> CreateLogStreamResponse)
-> Generic CreateLogStreamResponse
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