{-# 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-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 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 specify and control the number of shards that a stream is composed
-- of. 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 AWS
-- account used by the application. It is also scoped by AWS 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 AWS 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 AWS Support>.
--
-- You can use @DescribeStream@ 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_streamName,
    createStream_shardCount,

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

import qualified Amazonka.Core as Core
import Amazonka.Kinesis.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

-- | Represents the input for @CreateStream@.
--
-- /See:/ 'newCreateStream' smart constructor.
data CreateStream = CreateStream'
  { -- | A name to identify the stream. The stream name is scoped to the AWS
    -- account used by the application that creates the stream. It is also
    -- scoped by AWS Region. That is, two streams in two different AWS accounts
    -- can have the same name. Two streams in the same AWS account but in two
    -- different Regions can also have the same name.
    CreateStream -> Text
streamName :: Prelude.Text,
    -- | 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 -> Natural
shardCount :: Prelude.Natural
  }
  deriving (CreateStream -> CreateStream -> Bool
(CreateStream -> CreateStream -> Bool)
-> (CreateStream -> CreateStream -> Bool) -> Eq CreateStream
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]
(Int -> ReadS CreateStream)
-> ReadS [CreateStream]
-> ReadPrec CreateStream
-> ReadPrec [CreateStream]
-> Read 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
(Int -> CreateStream -> ShowS)
-> (CreateStream -> String)
-> ([CreateStream] -> ShowS)
-> Show CreateStream
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. CreateStream -> Rep CreateStream x)
-> (forall x. Rep CreateStream x -> CreateStream)
-> Generic CreateStream
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:
--
-- 'streamName', 'createStream_streamName' - A name to identify the stream. The stream name is scoped to the AWS
-- account used by the application that creates the stream. It is also
-- scoped by AWS Region. That is, two streams in two different AWS accounts
-- can have the same name. Two streams in the same AWS account but in two
-- different Regions can also have the same name.
--
-- '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.
newCreateStream ::
  -- | 'streamName'
  Prelude.Text ->
  -- | 'shardCount'
  Prelude.Natural ->
  CreateStream
newCreateStream :: Text -> Natural -> CreateStream
newCreateStream Text
pStreamName_ Natural
pShardCount_ =
  CreateStream' :: Text -> Natural -> CreateStream
CreateStream'
    { $sel:streamName:CreateStream' :: Text
streamName = Text
pStreamName_,
      $sel:shardCount:CreateStream' :: Natural
shardCount = Natural
pShardCount_
    }

-- | A name to identify the stream. The stream name is scoped to the AWS
-- account used by the application that creates the stream. It is also
-- scoped by AWS Region. That is, two streams in two different AWS accounts
-- can have the same name. Two streams in the same AWS account but in two
-- different Regions can also have the same name.
createStream_streamName :: Lens.Lens' CreateStream Prelude.Text
createStream_streamName :: (Text -> f Text) -> CreateStream -> f CreateStream
createStream_streamName = (CreateStream -> Text)
-> (CreateStream -> Text -> CreateStream)
-> Lens CreateStream CreateStream Text Text
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)

-- | 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.Natural
createStream_shardCount :: (Natural -> f Natural) -> CreateStream -> f CreateStream
createStream_shardCount = (CreateStream -> Natural)
-> (CreateStream -> Natural -> CreateStream)
-> Lens CreateStream CreateStream Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStream' {Natural
shardCount :: Natural
$sel:shardCount:CreateStream' :: CreateStream -> Natural
shardCount} -> Natural
shardCount) (\s :: CreateStream
s@CreateStream' {} Natural
a -> CreateStream
s {$sel:shardCount:CreateStream' :: Natural
shardCount = Natural
a} :: CreateStream)

instance Core.AWSRequest CreateStream where
  type AWSResponse CreateStream = CreateStreamResponse
  request :: CreateStream -> Request CreateStream
request = Service -> CreateStream -> Request CreateStream
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateStream)))
response = AWSResponse CreateStream
-> Logger
-> Service
-> Proxy CreateStream
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateStream)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse CreateStream
CreateStreamResponse
CreateStreamResponse'

instance Prelude.Hashable CreateStream

instance Prelude.NFData CreateStream

instance Core.ToHeaders CreateStream where
  toHeaders :: CreateStream -> [Header]
toHeaders =
    [Header] -> CreateStream -> [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
"Kinesis_20131202.CreateStream" ::
                          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 CreateStream where
  toJSON :: CreateStream -> Value
toJSON CreateStream' {Natural
Text
shardCount :: Natural
streamName :: Text
$sel:shardCount:CreateStream' :: CreateStream -> Natural
$sel:streamName:CreateStream' :: CreateStream -> 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
"StreamName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
streamName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ShardCount" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
shardCount)
          ]
      )

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

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

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