{-# 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.Kinesis.CreateStream
-- 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 Kinesis data stream. A stream captures and transports data
-- records that are continuously emitted from different data sources or
-- /producers/. Scale-out within a stream is explicitly supported by means
-- of shards, which are uniquely identified groups of data records in a
-- stream.
--
-- You can create your data stream using either on-demand or provisioned
-- capacity mode. Data streams with an on-demand mode require no capacity
-- planning and automatically scale to handle gigabytes of write and read
-- throughput per minute. With the on-demand mode, Kinesis Data Streams
-- automatically manages the shards in order to provide the necessary
-- throughput. For the data streams with a provisioned mode, you must
-- specify the number of shards for the data stream. Each shard can support
-- reads up to five transactions per second, up to a maximum data read
-- total of 2 MiB per second. Each shard can support writes up to 1,000
-- records per second, up to a maximum data write total of 1 MiB per
-- second. If the amount of data input increases or decreases, you can add
-- or remove shards.
--
-- The stream name identifies the stream. The name is scoped to the Amazon
-- Web Services account used by the application. It is also scoped by
-- Amazon Web Services Region. That is, two streams in two different
-- accounts can have the same name, and two streams in the same account,
-- but in two different Regions, can have the same name.
--
-- @CreateStream@ is an asynchronous operation. Upon receiving a
-- @CreateStream@ request, Kinesis Data Streams immediately returns and
-- sets the stream status to @CREATING@. After the stream is created,
-- Kinesis Data Streams sets the stream status to @ACTIVE@. You should
-- perform read and write operations only on an @ACTIVE@ stream.
--
-- You receive a @LimitExceededException@ when making a @CreateStream@
-- request when you try to do one of the following:
--
-- -   Have more than five streams in the @CREATING@ state at any point in
--     time.
--
-- -   Create more shards than are authorized for your account.
--
-- For the default shard limit for an Amazon Web Services account, see
-- <https://docs.aws.amazon.com/kinesis/latest/dev/service-sizes-and-limits.html Amazon Kinesis Data Streams Limits>
-- in the /Amazon Kinesis Data Streams Developer Guide/. To increase this
-- limit,
-- <https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html contact Amazon Web Services Support>.
--
-- You can use DescribeStreamSummary to check the stream status, which is
-- returned in @StreamStatus@.
--
-- CreateStream has a limit of five transactions per second per account.
module Amazonka.Kinesis.CreateStream
  ( -- * Creating a Request
    CreateStream (..),
    newCreateStream,

    -- * Request Lenses
    createStream_shardCount,
    createStream_streamModeDetails,
    createStream_streamName,

    -- * Destructuring the Response
    CreateStreamResponse (..),
    newCreateStreamResponse,
  )
where

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

-- | Represents the input for @CreateStream@.
--
-- /See:/ 'newCreateStream' smart constructor.
data CreateStream = CreateStream'
  { -- | The number of shards that the stream will use. The throughput of the
    -- stream is a function of the number of shards; more shards are required
    -- for greater provisioned throughput.
    CreateStream -> Maybe Natural
shardCount :: Prelude.Maybe Prelude.Natural,
    -- | Indicates the capacity mode of the data stream. Currently, in Kinesis
    -- Data Streams, you can choose between an __on-demand__ capacity mode and
    -- a __provisioned__ capacity mode for your data streams.
    CreateStream -> Maybe StreamModeDetails
streamModeDetails :: Prelude.Maybe StreamModeDetails,
    -- | A name to identify the stream. The stream name is scoped to the Amazon
    -- Web Services account used by the application that creates the stream. It
    -- is also scoped by Amazon Web Services Region. That is, two streams in
    -- two different Amazon Web Services accounts can have the same name. Two
    -- streams in the same Amazon Web Services account but in two different
    -- Regions can also have the same name.
    CreateStream -> Text
streamName :: Prelude.Text
  }
  deriving (CreateStream -> CreateStream -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateStream -> CreateStream -> Bool
$c/= :: CreateStream -> CreateStream -> Bool
== :: CreateStream -> CreateStream -> Bool
$c== :: CreateStream -> CreateStream -> Bool
Prelude.Eq, ReadPrec [CreateStream]
ReadPrec CreateStream
Int -> ReadS CreateStream
ReadS [CreateStream]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateStream]
$creadListPrec :: ReadPrec [CreateStream]
readPrec :: ReadPrec CreateStream
$creadPrec :: ReadPrec CreateStream
readList :: ReadS [CreateStream]
$creadList :: ReadS [CreateStream]
readsPrec :: Int -> ReadS CreateStream
$creadsPrec :: Int -> ReadS CreateStream
Prelude.Read, Int -> CreateStream -> ShowS
[CreateStream] -> ShowS
CreateStream -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateStream] -> ShowS
$cshowList :: [CreateStream] -> ShowS
show :: CreateStream -> String
$cshow :: CreateStream -> String
showsPrec :: Int -> CreateStream -> ShowS
$cshowsPrec :: Int -> CreateStream -> ShowS
Prelude.Show, forall x. Rep CreateStream x -> CreateStream
forall x. CreateStream -> Rep CreateStream x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateStream x -> CreateStream
$cfrom :: forall x. CreateStream -> Rep CreateStream x
Prelude.Generic)

-- |
-- Create a value of 'CreateStream' 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:
--
-- 'shardCount', 'createStream_shardCount' - The number of shards that the stream will use. The throughput of the
-- stream is a function of the number of shards; more shards are required
-- for greater provisioned throughput.
--
-- 'streamModeDetails', 'createStream_streamModeDetails' - Indicates the capacity mode of the data stream. Currently, in Kinesis
-- Data Streams, you can choose between an __on-demand__ capacity mode and
-- a __provisioned__ capacity mode for your data streams.
--
-- 'streamName', 'createStream_streamName' - A name to identify the stream. The stream name is scoped to the Amazon
-- Web Services account used by the application that creates the stream. It
-- is also scoped by Amazon Web Services Region. That is, two streams in
-- two different Amazon Web Services accounts can have the same name. Two
-- streams in the same Amazon Web Services account but in two different
-- Regions can also have the same name.
newCreateStream ::
  -- | 'streamName'
  Prelude.Text ->
  CreateStream
newCreateStream :: Text -> CreateStream
newCreateStream Text
pStreamName_ =
  CreateStream'
    { $sel:shardCount:CreateStream' :: Maybe Natural
shardCount = forall a. Maybe a
Prelude.Nothing,
      $sel:streamModeDetails:CreateStream' :: Maybe StreamModeDetails
streamModeDetails = forall a. Maybe a
Prelude.Nothing,
      $sel:streamName:CreateStream' :: Text
streamName = Text
pStreamName_
    }

-- | The number of shards that the stream will use. The throughput of the
-- stream is a function of the number of shards; more shards are required
-- for greater provisioned throughput.
createStream_shardCount :: Lens.Lens' CreateStream (Prelude.Maybe Prelude.Natural)
createStream_shardCount :: Lens' CreateStream (Maybe Natural)
createStream_shardCount = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStream' {Maybe Natural
shardCount :: Maybe Natural
$sel:shardCount:CreateStream' :: CreateStream -> Maybe Natural
shardCount} -> Maybe Natural
shardCount) (\s :: CreateStream
s@CreateStream' {} Maybe Natural
a -> CreateStream
s {$sel:shardCount:CreateStream' :: Maybe Natural
shardCount = Maybe Natural
a} :: CreateStream)

-- | Indicates the capacity mode of the data stream. Currently, in Kinesis
-- Data Streams, you can choose between an __on-demand__ capacity mode and
-- a __provisioned__ capacity mode for your data streams.
createStream_streamModeDetails :: Lens.Lens' CreateStream (Prelude.Maybe StreamModeDetails)
createStream_streamModeDetails :: Lens' CreateStream (Maybe StreamModeDetails)
createStream_streamModeDetails = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStream' {Maybe StreamModeDetails
streamModeDetails :: Maybe StreamModeDetails
$sel:streamModeDetails:CreateStream' :: CreateStream -> Maybe StreamModeDetails
streamModeDetails} -> Maybe StreamModeDetails
streamModeDetails) (\s :: CreateStream
s@CreateStream' {} Maybe StreamModeDetails
a -> CreateStream
s {$sel:streamModeDetails:CreateStream' :: Maybe StreamModeDetails
streamModeDetails = Maybe StreamModeDetails
a} :: CreateStream)

-- | A name to identify the stream. The stream name is scoped to the Amazon
-- Web Services account used by the application that creates the stream. It
-- is also scoped by Amazon Web Services Region. That is, two streams in
-- two different Amazon Web Services accounts can have the same name. Two
-- streams in the same Amazon Web Services account but in two different
-- Regions can also have the same name.
createStream_streamName :: Lens.Lens' CreateStream Prelude.Text
createStream_streamName :: Lens' CreateStream Text
createStream_streamName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStream' {Text
streamName :: Text
$sel:streamName:CreateStream' :: CreateStream -> Text
streamName} -> Text
streamName) (\s :: CreateStream
s@CreateStream' {} Text
a -> CreateStream
s {$sel:streamName:CreateStream' :: Text
streamName = Text
a} :: CreateStream)

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

instance Prelude.Hashable CreateStream where
  hashWithSalt :: Int -> CreateStream -> Int
hashWithSalt Int
_salt CreateStream' {Maybe Natural
Maybe StreamModeDetails
Text
streamName :: Text
streamModeDetails :: Maybe StreamModeDetails
shardCount :: Maybe Natural
$sel:streamName:CreateStream' :: CreateStream -> Text
$sel:streamModeDetails:CreateStream' :: CreateStream -> Maybe StreamModeDetails
$sel:shardCount:CreateStream' :: CreateStream -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
shardCount
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StreamModeDetails
streamModeDetails
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
streamName

instance Prelude.NFData CreateStream where
  rnf :: CreateStream -> ()
rnf CreateStream' {Maybe Natural
Maybe StreamModeDetails
Text
streamName :: Text
streamModeDetails :: Maybe StreamModeDetails
shardCount :: Maybe Natural
$sel:streamName:CreateStream' :: CreateStream -> Text
$sel:streamModeDetails:CreateStream' :: CreateStream -> Maybe StreamModeDetails
$sel:shardCount:CreateStream' :: CreateStream -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
shardCount
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe StreamModeDetails
streamModeDetails
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
streamName

instance Data.ToHeaders CreateStream where
  toHeaders :: CreateStream -> [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
"Kinesis_20131202.CreateStream" ::
                          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 CreateStream where
  toJSON :: CreateStream -> Value
toJSON CreateStream' {Maybe Natural
Maybe StreamModeDetails
Text
streamName :: Text
streamModeDetails :: Maybe StreamModeDetails
shardCount :: Maybe Natural
$sel:streamName:CreateStream' :: CreateStream -> Text
$sel:streamModeDetails:CreateStream' :: CreateStream -> Maybe StreamModeDetails
$sel:shardCount:CreateStream' :: CreateStream -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ShardCount" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
shardCount,
            (Key
"StreamModeDetails" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe StreamModeDetails
streamModeDetails,
            forall a. a -> Maybe a
Prelude.Just (Key
"StreamName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
streamName)
          ]
      )

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

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

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

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

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