{-# 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.EC2.StartInstances
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts an Amazon EBS-backed instance that you\'ve previously stopped.
--
-- Instances that use Amazon EBS volumes as their root devices can be
-- quickly stopped and started. When an instance is stopped, the compute
-- resources are released and you are not billed for instance usage.
-- However, your root partition Amazon EBS volume remains and continues to
-- persist your data, and you are charged for Amazon EBS volume usage. You
-- can restart your instance at any time. Every time you start your
-- instance, Amazon EC2 charges a one-minute minimum for instance usage,
-- and thereafter charges per second for instance usage.
--
-- Before stopping an instance, make sure it is in a state from which it
-- can be restarted. Stopping an instance does not preserve data stored in
-- RAM.
--
-- Performing this operation on an instance that uses an instance store as
-- its root device returns an error.
--
-- If you attempt to start a T3 instance with @host@ tenancy and the
-- @unlimted@ CPU credit option, the request fails. The @unlimited@ CPU
-- credit option is not supported on Dedicated Hosts. Before you start the
-- instance, either change its CPU credit option to @standard@, or change
-- its tenancy to @default@ or @dedicated@.
--
-- For more information, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html Stop and start your instance>
-- in the /Amazon EC2 User Guide/.
module Amazonka.EC2.StartInstances
  ( -- * Creating a Request
    StartInstances (..),
    newStartInstances,

    -- * Request Lenses
    startInstances_additionalInfo,
    startInstances_dryRun,
    startInstances_instanceIds,

    -- * Destructuring the Response
    StartInstancesResponse (..),
    newStartInstancesResponse,

    -- * Response Lenses
    startInstancesResponse_startingInstances,
    startInstancesResponse_httpStatus,
  )
where

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

-- | /See:/ 'newStartInstances' smart constructor.
data StartInstances = StartInstances'
  { -- | Reserved.
    StartInstances -> Maybe Text
additionalInfo :: Prelude.Maybe Prelude.Text,
    -- | Checks whether you have the required permissions for the action, without
    -- actually making the request, and provides an error response. If you have
    -- the required permissions, the error response is @DryRunOperation@.
    -- Otherwise, it is @UnauthorizedOperation@.
    StartInstances -> Maybe Bool
dryRun :: Prelude.Maybe Prelude.Bool,
    -- | The IDs of the instances.
    StartInstances -> [Text]
instanceIds :: [Prelude.Text]
  }
  deriving (StartInstances -> StartInstances -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartInstances -> StartInstances -> Bool
$c/= :: StartInstances -> StartInstances -> Bool
== :: StartInstances -> StartInstances -> Bool
$c== :: StartInstances -> StartInstances -> Bool
Prelude.Eq, ReadPrec [StartInstances]
ReadPrec StartInstances
Int -> ReadS StartInstances
ReadS [StartInstances]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartInstances]
$creadListPrec :: ReadPrec [StartInstances]
readPrec :: ReadPrec StartInstances
$creadPrec :: ReadPrec StartInstances
readList :: ReadS [StartInstances]
$creadList :: ReadS [StartInstances]
readsPrec :: Int -> ReadS StartInstances
$creadsPrec :: Int -> ReadS StartInstances
Prelude.Read, Int -> StartInstances -> ShowS
[StartInstances] -> ShowS
StartInstances -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartInstances] -> ShowS
$cshowList :: [StartInstances] -> ShowS
show :: StartInstances -> String
$cshow :: StartInstances -> String
showsPrec :: Int -> StartInstances -> ShowS
$cshowsPrec :: Int -> StartInstances -> ShowS
Prelude.Show, forall x. Rep StartInstances x -> StartInstances
forall x. StartInstances -> Rep StartInstances x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartInstances x -> StartInstances
$cfrom :: forall x. StartInstances -> Rep StartInstances x
Prelude.Generic)

-- |
-- Create a value of 'StartInstances' 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:
--
-- 'additionalInfo', 'startInstances_additionalInfo' - Reserved.
--
-- 'dryRun', 'startInstances_dryRun' - Checks whether you have the required permissions for the action, without
-- actually making the request, and provides an error response. If you have
-- the required permissions, the error response is @DryRunOperation@.
-- Otherwise, it is @UnauthorizedOperation@.
--
-- 'instanceIds', 'startInstances_instanceIds' - The IDs of the instances.
newStartInstances ::
  StartInstances
newStartInstances :: StartInstances
newStartInstances =
  StartInstances'
    { $sel:additionalInfo:StartInstances' :: Maybe Text
additionalInfo = forall a. Maybe a
Prelude.Nothing,
      $sel:dryRun:StartInstances' :: Maybe Bool
dryRun = forall a. Maybe a
Prelude.Nothing,
      $sel:instanceIds:StartInstances' :: [Text]
instanceIds = forall a. Monoid a => a
Prelude.mempty
    }

-- | Reserved.
startInstances_additionalInfo :: Lens.Lens' StartInstances (Prelude.Maybe Prelude.Text)
startInstances_additionalInfo :: Lens' StartInstances (Maybe Text)
startInstances_additionalInfo = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstances' {Maybe Text
additionalInfo :: Maybe Text
$sel:additionalInfo:StartInstances' :: StartInstances -> Maybe Text
additionalInfo} -> Maybe Text
additionalInfo) (\s :: StartInstances
s@StartInstances' {} Maybe Text
a -> StartInstances
s {$sel:additionalInfo:StartInstances' :: Maybe Text
additionalInfo = Maybe Text
a} :: StartInstances)

-- | Checks whether you have the required permissions for the action, without
-- actually making the request, and provides an error response. If you have
-- the required permissions, the error response is @DryRunOperation@.
-- Otherwise, it is @UnauthorizedOperation@.
startInstances_dryRun :: Lens.Lens' StartInstances (Prelude.Maybe Prelude.Bool)
startInstances_dryRun :: Lens' StartInstances (Maybe Bool)
startInstances_dryRun = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstances' {Maybe Bool
dryRun :: Maybe Bool
$sel:dryRun:StartInstances' :: StartInstances -> Maybe Bool
dryRun} -> Maybe Bool
dryRun) (\s :: StartInstances
s@StartInstances' {} Maybe Bool
a -> StartInstances
s {$sel:dryRun:StartInstances' :: Maybe Bool
dryRun = Maybe Bool
a} :: StartInstances)

-- | The IDs of the instances.
startInstances_instanceIds :: Lens.Lens' StartInstances [Prelude.Text]
startInstances_instanceIds :: Lens' StartInstances [Text]
startInstances_instanceIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstances' {[Text]
instanceIds :: [Text]
$sel:instanceIds:StartInstances' :: StartInstances -> [Text]
instanceIds} -> [Text]
instanceIds) (\s :: StartInstances
s@StartInstances' {} [Text]
a -> StartInstances
s {$sel:instanceIds:StartInstances' :: [Text]
instanceIds = [Text]
a} :: StartInstances) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest StartInstances where
  type
    AWSResponse StartInstances =
      StartInstancesResponse
  request :: (Service -> Service) -> StartInstances -> Request StartInstances
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy StartInstances
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartInstances)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXML
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [InstanceStateChange] -> Int -> StartInstancesResponse
StartInstancesResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x
                            forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"instancesSet"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                            forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (forall a. FromXML a => Text -> [Node] -> Either String [a]
Data.parseXMLList Text
"item")
                        )
            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 StartInstances where
  hashWithSalt :: Int -> StartInstances -> Int
hashWithSalt Int
_salt StartInstances' {[Text]
Maybe Bool
Maybe Text
instanceIds :: [Text]
dryRun :: Maybe Bool
additionalInfo :: Maybe Text
$sel:instanceIds:StartInstances' :: StartInstances -> [Text]
$sel:dryRun:StartInstances' :: StartInstances -> Maybe Bool
$sel:additionalInfo:StartInstances' :: StartInstances -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
additionalInfo
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
dryRun
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Text]
instanceIds

instance Prelude.NFData StartInstances where
  rnf :: StartInstances -> ()
rnf StartInstances' {[Text]
Maybe Bool
Maybe Text
instanceIds :: [Text]
dryRun :: Maybe Bool
additionalInfo :: Maybe Text
$sel:instanceIds:StartInstances' :: StartInstances -> [Text]
$sel:dryRun:StartInstances' :: StartInstances -> Maybe Bool
$sel:additionalInfo:StartInstances' :: StartInstances -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
additionalInfo
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
dryRun
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Text]
instanceIds

instance Data.ToHeaders StartInstances where
  toHeaders :: StartInstances -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery StartInstances where
  toQuery :: StartInstances -> QueryString
toQuery StartInstances' {[Text]
Maybe Bool
Maybe Text
instanceIds :: [Text]
dryRun :: Maybe Bool
additionalInfo :: Maybe Text
$sel:instanceIds:StartInstances' :: StartInstances -> [Text]
$sel:dryRun:StartInstances' :: StartInstances -> Maybe Bool
$sel:additionalInfo:StartInstances' :: StartInstances -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"StartInstances" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2016-11-15" :: Prelude.ByteString),
        ByteString
"AdditionalInfo" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
additionalInfo,
        ByteString
"DryRun" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Bool
dryRun,
        forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"InstanceId" [Text]
instanceIds
      ]

-- | /See:/ 'newStartInstancesResponse' smart constructor.
data StartInstancesResponse = StartInstancesResponse'
  { -- | Information about the started instances.
    StartInstancesResponse -> Maybe [InstanceStateChange]
startingInstances :: Prelude.Maybe [InstanceStateChange],
    -- | The response's http status code.
    StartInstancesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartInstancesResponse -> StartInstancesResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartInstancesResponse -> StartInstancesResponse -> Bool
$c/= :: StartInstancesResponse -> StartInstancesResponse -> Bool
== :: StartInstancesResponse -> StartInstancesResponse -> Bool
$c== :: StartInstancesResponse -> StartInstancesResponse -> Bool
Prelude.Eq, ReadPrec [StartInstancesResponse]
ReadPrec StartInstancesResponse
Int -> ReadS StartInstancesResponse
ReadS [StartInstancesResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartInstancesResponse]
$creadListPrec :: ReadPrec [StartInstancesResponse]
readPrec :: ReadPrec StartInstancesResponse
$creadPrec :: ReadPrec StartInstancesResponse
readList :: ReadS [StartInstancesResponse]
$creadList :: ReadS [StartInstancesResponse]
readsPrec :: Int -> ReadS StartInstancesResponse
$creadsPrec :: Int -> ReadS StartInstancesResponse
Prelude.Read, Int -> StartInstancesResponse -> ShowS
[StartInstancesResponse] -> ShowS
StartInstancesResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartInstancesResponse] -> ShowS
$cshowList :: [StartInstancesResponse] -> ShowS
show :: StartInstancesResponse -> String
$cshow :: StartInstancesResponse -> String
showsPrec :: Int -> StartInstancesResponse -> ShowS
$cshowsPrec :: Int -> StartInstancesResponse -> ShowS
Prelude.Show, forall x. Rep StartInstancesResponse x -> StartInstancesResponse
forall x. StartInstancesResponse -> Rep StartInstancesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartInstancesResponse x -> StartInstancesResponse
$cfrom :: forall x. StartInstancesResponse -> Rep StartInstancesResponse x
Prelude.Generic)

-- |
-- Create a value of 'StartInstancesResponse' 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:
--
-- 'startingInstances', 'startInstancesResponse_startingInstances' - Information about the started instances.
--
-- 'httpStatus', 'startInstancesResponse_httpStatus' - The response's http status code.
newStartInstancesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartInstancesResponse
newStartInstancesResponse :: Int -> StartInstancesResponse
newStartInstancesResponse Int
pHttpStatus_ =
  StartInstancesResponse'
    { $sel:startingInstances:StartInstancesResponse' :: Maybe [InstanceStateChange]
startingInstances =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartInstancesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the started instances.
startInstancesResponse_startingInstances :: Lens.Lens' StartInstancesResponse (Prelude.Maybe [InstanceStateChange])
startInstancesResponse_startingInstances :: Lens' StartInstancesResponse (Maybe [InstanceStateChange])
startInstancesResponse_startingInstances = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstancesResponse' {Maybe [InstanceStateChange]
startingInstances :: Maybe [InstanceStateChange]
$sel:startingInstances:StartInstancesResponse' :: StartInstancesResponse -> Maybe [InstanceStateChange]
startingInstances} -> Maybe [InstanceStateChange]
startingInstances) (\s :: StartInstancesResponse
s@StartInstancesResponse' {} Maybe [InstanceStateChange]
a -> StartInstancesResponse
s {$sel:startingInstances:StartInstancesResponse' :: Maybe [InstanceStateChange]
startingInstances = Maybe [InstanceStateChange]
a} :: StartInstancesResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
startInstancesResponse_httpStatus :: Lens.Lens' StartInstancesResponse Prelude.Int
startInstancesResponse_httpStatus :: Lens' StartInstancesResponse Int
startInstancesResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartInstancesResponse' {Int
httpStatus :: Int
$sel:httpStatus:StartInstancesResponse' :: StartInstancesResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: StartInstancesResponse
s@StartInstancesResponse' {} Int
a -> StartInstancesResponse
s {$sel:httpStatus:StartInstancesResponse' :: Int
httpStatus = Int
a} :: StartInstancesResponse)

instance Prelude.NFData StartInstancesResponse where
  rnf :: StartInstancesResponse -> ()
rnf StartInstancesResponse' {Int
Maybe [InstanceStateChange]
httpStatus :: Int
startingInstances :: Maybe [InstanceStateChange]
$sel:httpStatus:StartInstancesResponse' :: StartInstancesResponse -> Int
$sel:startingInstances:StartInstancesResponse' :: StartInstancesResponse -> Maybe [InstanceStateChange]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [InstanceStateChange]
startingInstances
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus