{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SageMaker.Types.ResourceConfig
-- 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)
module Amazonka.SageMaker.Types.ResourceConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SageMaker.Types.TrainingInstanceType

-- | Describes the resources, including ML compute instances and ML storage
-- volumes, to use for model training.
--
-- /See:/ 'newResourceConfig' smart constructor.
data ResourceConfig = ResourceConfig'
  { -- | The Amazon Web Services KMS key that Amazon SageMaker uses to encrypt
    -- data on the storage volume attached to the ML compute instance(s) that
    -- run the training job.
    --
    -- Certain Nitro-based instances include local storage, dependent on the
    -- instance type. Local storage volumes are encrypted using a hardware
    -- module on the instance. You can\'t request a @VolumeKmsKeyId@ when using
    -- an instance type with local storage.
    --
    -- For a list of instance types that support local instance storage, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes Instance Store Volumes>.
    --
    -- For more information about local instance storage encryption, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ssd-instance-store.html SSD Instance Store Volumes>.
    --
    -- The @VolumeKmsKeyId@ can be in any of the following formats:
    --
    -- -   \/\/ KMS Key ID
    --
    --     @\"1234abcd-12ab-34cd-56ef-1234567890ab\"@
    --
    -- -   \/\/ Amazon Resource Name (ARN) of a KMS Key
    --
    --     @\"arn:aws:kms:us-west-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab\"@
    ResourceConfig -> Maybe Text
volumeKmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The ML compute instance type.
    ResourceConfig -> TrainingInstanceType
instanceType :: TrainingInstanceType,
    -- | The number of ML compute instances to use. For distributed training,
    -- provide a value greater than 1.
    ResourceConfig -> Natural
instanceCount :: Prelude.Natural,
    -- | The size of the ML storage volume that you want to provision.
    --
    -- ML storage volumes store model artifacts and incremental states.
    -- Training algorithms might also use the ML storage volume for scratch
    -- space. If you want to store the training data in the ML storage volume,
    -- choose @File@ as the @TrainingInputMode@ in the algorithm specification.
    --
    -- You must specify sufficient ML storage for your scenario.
    --
    -- Amazon SageMaker supports only the General Purpose SSD (gp2) ML storage
    -- volume type.
    --
    -- Certain Nitro-based instances include local storage with a fixed total
    -- size, dependent on the instance type. When using these instances for
    -- training, Amazon SageMaker mounts the local instance storage instead of
    -- Amazon EBS gp2 storage. You can\'t request a @VolumeSizeInGB@ greater
    -- than the total size of the local instance storage.
    --
    -- For a list of instance types that support local instance storage,
    -- including the total size per instance type, see
    -- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes Instance Store Volumes>.
    ResourceConfig -> Natural
volumeSizeInGB :: Prelude.Natural
  }
  deriving (ResourceConfig -> ResourceConfig -> Bool
(ResourceConfig -> ResourceConfig -> Bool)
-> (ResourceConfig -> ResourceConfig -> Bool) -> Eq ResourceConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceConfig -> ResourceConfig -> Bool
$c/= :: ResourceConfig -> ResourceConfig -> Bool
== :: ResourceConfig -> ResourceConfig -> Bool
$c== :: ResourceConfig -> ResourceConfig -> Bool
Prelude.Eq, ReadPrec [ResourceConfig]
ReadPrec ResourceConfig
Int -> ReadS ResourceConfig
ReadS [ResourceConfig]
(Int -> ReadS ResourceConfig)
-> ReadS [ResourceConfig]
-> ReadPrec ResourceConfig
-> ReadPrec [ResourceConfig]
-> Read ResourceConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceConfig]
$creadListPrec :: ReadPrec [ResourceConfig]
readPrec :: ReadPrec ResourceConfig
$creadPrec :: ReadPrec ResourceConfig
readList :: ReadS [ResourceConfig]
$creadList :: ReadS [ResourceConfig]
readsPrec :: Int -> ReadS ResourceConfig
$creadsPrec :: Int -> ReadS ResourceConfig
Prelude.Read, Int -> ResourceConfig -> ShowS
[ResourceConfig] -> ShowS
ResourceConfig -> String
(Int -> ResourceConfig -> ShowS)
-> (ResourceConfig -> String)
-> ([ResourceConfig] -> ShowS)
-> Show ResourceConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceConfig] -> ShowS
$cshowList :: [ResourceConfig] -> ShowS
show :: ResourceConfig -> String
$cshow :: ResourceConfig -> String
showsPrec :: Int -> ResourceConfig -> ShowS
$cshowsPrec :: Int -> ResourceConfig -> ShowS
Prelude.Show, (forall x. ResourceConfig -> Rep ResourceConfig x)
-> (forall x. Rep ResourceConfig x -> ResourceConfig)
-> Generic ResourceConfig
forall x. Rep ResourceConfig x -> ResourceConfig
forall x. ResourceConfig -> Rep ResourceConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceConfig x -> ResourceConfig
$cfrom :: forall x. ResourceConfig -> Rep ResourceConfig x
Prelude.Generic)

-- |
-- Create a value of 'ResourceConfig' 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:
--
-- 'volumeKmsKeyId', 'resourceConfig_volumeKmsKeyId' - The Amazon Web Services KMS key that Amazon SageMaker uses to encrypt
-- data on the storage volume attached to the ML compute instance(s) that
-- run the training job.
--
-- Certain Nitro-based instances include local storage, dependent on the
-- instance type. Local storage volumes are encrypted using a hardware
-- module on the instance. You can\'t request a @VolumeKmsKeyId@ when using
-- an instance type with local storage.
--
-- For a list of instance types that support local instance storage, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes Instance Store Volumes>.
--
-- For more information about local instance storage encryption, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ssd-instance-store.html SSD Instance Store Volumes>.
--
-- The @VolumeKmsKeyId@ can be in any of the following formats:
--
-- -   \/\/ KMS Key ID
--
--     @\"1234abcd-12ab-34cd-56ef-1234567890ab\"@
--
-- -   \/\/ Amazon Resource Name (ARN) of a KMS Key
--
--     @\"arn:aws:kms:us-west-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab\"@
--
-- 'instanceType', 'resourceConfig_instanceType' - The ML compute instance type.
--
-- 'instanceCount', 'resourceConfig_instanceCount' - The number of ML compute instances to use. For distributed training,
-- provide a value greater than 1.
--
-- 'volumeSizeInGB', 'resourceConfig_volumeSizeInGB' - The size of the ML storage volume that you want to provision.
--
-- ML storage volumes store model artifacts and incremental states.
-- Training algorithms might also use the ML storage volume for scratch
-- space. If you want to store the training data in the ML storage volume,
-- choose @File@ as the @TrainingInputMode@ in the algorithm specification.
--
-- You must specify sufficient ML storage for your scenario.
--
-- Amazon SageMaker supports only the General Purpose SSD (gp2) ML storage
-- volume type.
--
-- Certain Nitro-based instances include local storage with a fixed total
-- size, dependent on the instance type. When using these instances for
-- training, Amazon SageMaker mounts the local instance storage instead of
-- Amazon EBS gp2 storage. You can\'t request a @VolumeSizeInGB@ greater
-- than the total size of the local instance storage.
--
-- For a list of instance types that support local instance storage,
-- including the total size per instance type, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes Instance Store Volumes>.
newResourceConfig ::
  -- | 'instanceType'
  TrainingInstanceType ->
  -- | 'instanceCount'
  Prelude.Natural ->
  -- | 'volumeSizeInGB'
  Prelude.Natural ->
  ResourceConfig
newResourceConfig :: TrainingInstanceType -> Natural -> Natural -> ResourceConfig
newResourceConfig
  TrainingInstanceType
pInstanceType_
  Natural
pInstanceCount_
  Natural
pVolumeSizeInGB_ =
    ResourceConfig' :: Maybe Text
-> TrainingInstanceType -> Natural -> Natural -> ResourceConfig
ResourceConfig'
      { $sel:volumeKmsKeyId:ResourceConfig' :: Maybe Text
volumeKmsKeyId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:instanceType:ResourceConfig' :: TrainingInstanceType
instanceType = TrainingInstanceType
pInstanceType_,
        $sel:instanceCount:ResourceConfig' :: Natural
instanceCount = Natural
pInstanceCount_,
        $sel:volumeSizeInGB:ResourceConfig' :: Natural
volumeSizeInGB = Natural
pVolumeSizeInGB_
      }

-- | The Amazon Web Services KMS key that Amazon SageMaker uses to encrypt
-- data on the storage volume attached to the ML compute instance(s) that
-- run the training job.
--
-- Certain Nitro-based instances include local storage, dependent on the
-- instance type. Local storage volumes are encrypted using a hardware
-- module on the instance. You can\'t request a @VolumeKmsKeyId@ when using
-- an instance type with local storage.
--
-- For a list of instance types that support local instance storage, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes Instance Store Volumes>.
--
-- For more information about local instance storage encryption, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ssd-instance-store.html SSD Instance Store Volumes>.
--
-- The @VolumeKmsKeyId@ can be in any of the following formats:
--
-- -   \/\/ KMS Key ID
--
--     @\"1234abcd-12ab-34cd-56ef-1234567890ab\"@
--
-- -   \/\/ Amazon Resource Name (ARN) of a KMS Key
--
--     @\"arn:aws:kms:us-west-2:111122223333:key\/1234abcd-12ab-34cd-56ef-1234567890ab\"@
resourceConfig_volumeKmsKeyId :: Lens.Lens' ResourceConfig (Prelude.Maybe Prelude.Text)
resourceConfig_volumeKmsKeyId :: (Maybe Text -> f (Maybe Text))
-> ResourceConfig -> f ResourceConfig
resourceConfig_volumeKmsKeyId = (ResourceConfig -> Maybe Text)
-> (ResourceConfig -> Maybe Text -> ResourceConfig)
-> Lens ResourceConfig ResourceConfig (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceConfig' {Maybe Text
volumeKmsKeyId :: Maybe Text
$sel:volumeKmsKeyId:ResourceConfig' :: ResourceConfig -> Maybe Text
volumeKmsKeyId} -> Maybe Text
volumeKmsKeyId) (\s :: ResourceConfig
s@ResourceConfig' {} Maybe Text
a -> ResourceConfig
s {$sel:volumeKmsKeyId:ResourceConfig' :: Maybe Text
volumeKmsKeyId = Maybe Text
a} :: ResourceConfig)

-- | The ML compute instance type.
resourceConfig_instanceType :: Lens.Lens' ResourceConfig TrainingInstanceType
resourceConfig_instanceType :: (TrainingInstanceType -> f TrainingInstanceType)
-> ResourceConfig -> f ResourceConfig
resourceConfig_instanceType = (ResourceConfig -> TrainingInstanceType)
-> (ResourceConfig -> TrainingInstanceType -> ResourceConfig)
-> Lens
     ResourceConfig
     ResourceConfig
     TrainingInstanceType
     TrainingInstanceType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceConfig' {TrainingInstanceType
instanceType :: TrainingInstanceType
$sel:instanceType:ResourceConfig' :: ResourceConfig -> TrainingInstanceType
instanceType} -> TrainingInstanceType
instanceType) (\s :: ResourceConfig
s@ResourceConfig' {} TrainingInstanceType
a -> ResourceConfig
s {$sel:instanceType:ResourceConfig' :: TrainingInstanceType
instanceType = TrainingInstanceType
a} :: ResourceConfig)

-- | The number of ML compute instances to use. For distributed training,
-- provide a value greater than 1.
resourceConfig_instanceCount :: Lens.Lens' ResourceConfig Prelude.Natural
resourceConfig_instanceCount :: (Natural -> f Natural) -> ResourceConfig -> f ResourceConfig
resourceConfig_instanceCount = (ResourceConfig -> Natural)
-> (ResourceConfig -> Natural -> ResourceConfig)
-> Lens ResourceConfig ResourceConfig Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceConfig' {Natural
instanceCount :: Natural
$sel:instanceCount:ResourceConfig' :: ResourceConfig -> Natural
instanceCount} -> Natural
instanceCount) (\s :: ResourceConfig
s@ResourceConfig' {} Natural
a -> ResourceConfig
s {$sel:instanceCount:ResourceConfig' :: Natural
instanceCount = Natural
a} :: ResourceConfig)

-- | The size of the ML storage volume that you want to provision.
--
-- ML storage volumes store model artifacts and incremental states.
-- Training algorithms might also use the ML storage volume for scratch
-- space. If you want to store the training data in the ML storage volume,
-- choose @File@ as the @TrainingInputMode@ in the algorithm specification.
--
-- You must specify sufficient ML storage for your scenario.
--
-- Amazon SageMaker supports only the General Purpose SSD (gp2) ML storage
-- volume type.
--
-- Certain Nitro-based instances include local storage with a fixed total
-- size, dependent on the instance type. When using these instances for
-- training, Amazon SageMaker mounts the local instance storage instead of
-- Amazon EBS gp2 storage. You can\'t request a @VolumeSizeInGB@ greater
-- than the total size of the local instance storage.
--
-- For a list of instance types that support local instance storage,
-- including the total size per instance type, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#instance-store-volumes Instance Store Volumes>.
resourceConfig_volumeSizeInGB :: Lens.Lens' ResourceConfig Prelude.Natural
resourceConfig_volumeSizeInGB :: (Natural -> f Natural) -> ResourceConfig -> f ResourceConfig
resourceConfig_volumeSizeInGB = (ResourceConfig -> Natural)
-> (ResourceConfig -> Natural -> ResourceConfig)
-> Lens ResourceConfig ResourceConfig Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceConfig' {Natural
volumeSizeInGB :: Natural
$sel:volumeSizeInGB:ResourceConfig' :: ResourceConfig -> Natural
volumeSizeInGB} -> Natural
volumeSizeInGB) (\s :: ResourceConfig
s@ResourceConfig' {} Natural
a -> ResourceConfig
s {$sel:volumeSizeInGB:ResourceConfig' :: Natural
volumeSizeInGB = Natural
a} :: ResourceConfig)

instance Core.FromJSON ResourceConfig where
  parseJSON :: Value -> Parser ResourceConfig
parseJSON =
    String
-> (Object -> Parser ResourceConfig)
-> Value
-> Parser ResourceConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceConfig"
      ( \Object
x ->
          Maybe Text
-> TrainingInstanceType -> Natural -> Natural -> ResourceConfig
ResourceConfig'
            (Maybe Text
 -> TrainingInstanceType -> Natural -> Natural -> ResourceConfig)
-> Parser (Maybe Text)
-> Parser
     (TrainingInstanceType -> Natural -> Natural -> ResourceConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"VolumeKmsKeyId")
            Parser
  (TrainingInstanceType -> Natural -> Natural -> ResourceConfig)
-> Parser TrainingInstanceType
-> Parser (Natural -> Natural -> ResourceConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser TrainingInstanceType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"InstanceType")
            Parser (Natural -> Natural -> ResourceConfig)
-> Parser Natural -> Parser (Natural -> ResourceConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"InstanceCount")
            Parser (Natural -> ResourceConfig)
-> Parser Natural -> Parser ResourceConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"VolumeSizeInGB")
      )

instance Prelude.Hashable ResourceConfig

instance Prelude.NFData ResourceConfig

instance Core.ToJSON ResourceConfig where
  toJSON :: ResourceConfig -> Value
toJSON ResourceConfig' {Natural
Maybe Text
TrainingInstanceType
volumeSizeInGB :: Natural
instanceCount :: Natural
instanceType :: TrainingInstanceType
volumeKmsKeyId :: Maybe Text
$sel:volumeSizeInGB:ResourceConfig' :: ResourceConfig -> Natural
$sel:instanceCount:ResourceConfig' :: ResourceConfig -> Natural
$sel:instanceType:ResourceConfig' :: ResourceConfig -> TrainingInstanceType
$sel:volumeKmsKeyId:ResourceConfig' :: ResourceConfig -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"VolumeKmsKeyId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
volumeKmsKeyId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceType" Text -> TrainingInstanceType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= TrainingInstanceType
instanceType),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InstanceCount" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
instanceCount),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"VolumeSizeInGB" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
volumeSizeInGB)
          ]
      )