{-# 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.Synthetics.CreateCanary
-- 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 canary. Canaries are scripts that monitor your endpoints and
-- APIs from the outside-in. Canaries help you check the availability and
-- latency of your web services and troubleshoot anomalies by investigating
-- load time data, screenshots of the UI, logs, and metrics. You can set up
-- a canary to run continuously or just once.
--
-- Do not use @CreateCanary@ to modify an existing canary. Use
-- <https://docs.aws.amazon.com/AmazonSynthetics/latest/APIReference/API_UpdateCanary.html UpdateCanary>
-- instead.
--
-- To create canaries, you must have the @CloudWatchSyntheticsFullAccess@
-- policy. If you are creating a new IAM role for the canary, you also need
-- the @iam:CreateRole@, @iam:CreatePolicy@ and @iam:AttachRolePolicy@
-- permissions. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_Roles Necessary Roles and Permissions>.
--
-- Do not include secrets or proprietary information in your canary names.
-- The canary name makes up part of the Amazon Resource Name (ARN) for the
-- canary, and the ARN is included in outbound calls over the internet. For
-- more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/servicelens_canaries_security.html Security Considerations for Synthetics Canaries>.
module Amazonka.Synthetics.CreateCanary
  ( -- * Creating a Request
    CreateCanary (..),
    newCreateCanary,

    -- * Request Lenses
    createCanary_artifactConfig,
    createCanary_failureRetentionPeriodInDays,
    createCanary_runConfig,
    createCanary_successRetentionPeriodInDays,
    createCanary_tags,
    createCanary_vpcConfig,
    createCanary_name,
    createCanary_code,
    createCanary_artifactS3Location,
    createCanary_executionRoleArn,
    createCanary_schedule,
    createCanary_runtimeVersion,

    -- * Destructuring the Response
    CreateCanaryResponse (..),
    newCreateCanaryResponse,

    -- * Response Lenses
    createCanaryResponse_canary,
    createCanaryResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateCanary' smart constructor.
data CreateCanary = CreateCanary'
  { -- | A structure that contains the configuration for canary artifacts,
    -- including the encryption-at-rest settings for artifacts that the canary
    -- uploads to Amazon S3.
    CreateCanary -> Maybe ArtifactConfigInput
artifactConfig :: Prelude.Maybe ArtifactConfigInput,
    -- | The number of days to retain data about failed runs of this canary. If
    -- you omit this field, the default of 31 days is used. The valid range is
    -- 1 to 455 days.
    CreateCanary -> Maybe Natural
failureRetentionPeriodInDays :: Prelude.Maybe Prelude.Natural,
    -- | A structure that contains the configuration for individual canary runs,
    -- such as timeout value and environment variables.
    --
    -- The environment variables keys and values are not encrypted. Do not
    -- store sensitive information in this field.
    CreateCanary -> Maybe CanaryRunConfigInput
runConfig :: Prelude.Maybe CanaryRunConfigInput,
    -- | The number of days to retain data about successful runs of this canary.
    -- If you omit this field, the default of 31 days is used. The valid range
    -- is 1 to 455 days.
    CreateCanary -> Maybe Natural
successRetentionPeriodInDays :: Prelude.Maybe Prelude.Natural,
    -- | A list of key-value pairs to associate with the canary. You can
    -- associate as many as 50 tags with a canary.
    --
    -- Tags can help you organize and categorize your resources. You can also
    -- use them to scope user permissions, by granting a user permission to
    -- access or change only the resources that have certain tag values.
    CreateCanary -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | If this canary is to test an endpoint in a VPC, this structure contains
    -- information about the subnet and security groups of the VPC endpoint.
    -- For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_VPC.html Running a Canary in a VPC>.
    CreateCanary -> Maybe VpcConfigInput
vpcConfig :: Prelude.Maybe VpcConfigInput,
    -- | The name for this canary. Be sure to give it a descriptive name that
    -- distinguishes it from other canaries in your account.
    --
    -- Do not include secrets or proprietary information in your canary names.
    -- The canary name makes up part of the canary ARN, and the ARN is included
    -- in outbound calls over the internet. For more information, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/servicelens_canaries_security.html Security Considerations for Synthetics Canaries>.
    CreateCanary -> Text
name :: Prelude.Text,
    -- | A structure that includes the entry point from which the canary should
    -- start running your script. If the script is stored in an S3 bucket, the
    -- bucket name, key, and version are also included.
    CreateCanary -> CanaryCodeInput
code :: CanaryCodeInput,
    -- | The location in Amazon S3 where Synthetics stores artifacts from the
    -- test runs of this canary. Artifacts include the log file, screenshots,
    -- and HAR files. The name of the S3 bucket can\'t include a period (.).
    CreateCanary -> Text
artifactS3Location :: Prelude.Text,
    -- | The ARN of the IAM role to be used to run the canary. This role must
    -- already exist, and must include @lambda.amazonaws.com@ as a principal in
    -- the trust policy. The role must also have the following permissions:
    --
    -- -   @s3:PutObject@
    --
    -- -   @s3:GetBucketLocation@
    --
    -- -   @s3:ListAllMyBuckets@
    --
    -- -   @cloudwatch:PutMetricData@
    --
    -- -   @logs:CreateLogGroup@
    --
    -- -   @logs:CreateLogStream@
    --
    -- -   @logs:PutLogEvents@
    CreateCanary -> Text
executionRoleArn :: Prelude.Text,
    -- | A structure that contains information about how often the canary is to
    -- run and when these test runs are to stop.
    CreateCanary -> CanaryScheduleInput
schedule :: CanaryScheduleInput,
    -- | Specifies the runtime version to use for the canary. For a list of valid
    -- runtime versions and more information about runtime versions, see
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_Library.html Canary Runtime Versions>.
    CreateCanary -> Text
runtimeVersion :: Prelude.Text
  }
  deriving (CreateCanary -> CreateCanary -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCanary -> CreateCanary -> Bool
$c/= :: CreateCanary -> CreateCanary -> Bool
== :: CreateCanary -> CreateCanary -> Bool
$c== :: CreateCanary -> CreateCanary -> Bool
Prelude.Eq, ReadPrec [CreateCanary]
ReadPrec CreateCanary
Int -> ReadS CreateCanary
ReadS [CreateCanary]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateCanary]
$creadListPrec :: ReadPrec [CreateCanary]
readPrec :: ReadPrec CreateCanary
$creadPrec :: ReadPrec CreateCanary
readList :: ReadS [CreateCanary]
$creadList :: ReadS [CreateCanary]
readsPrec :: Int -> ReadS CreateCanary
$creadsPrec :: Int -> ReadS CreateCanary
Prelude.Read, Int -> CreateCanary -> ShowS
[CreateCanary] -> ShowS
CreateCanary -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCanary] -> ShowS
$cshowList :: [CreateCanary] -> ShowS
show :: CreateCanary -> String
$cshow :: CreateCanary -> String
showsPrec :: Int -> CreateCanary -> ShowS
$cshowsPrec :: Int -> CreateCanary -> ShowS
Prelude.Show, forall x. Rep CreateCanary x -> CreateCanary
forall x. CreateCanary -> Rep CreateCanary x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateCanary x -> CreateCanary
$cfrom :: forall x. CreateCanary -> Rep CreateCanary x
Prelude.Generic)

-- |
-- Create a value of 'CreateCanary' 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:
--
-- 'artifactConfig', 'createCanary_artifactConfig' - A structure that contains the configuration for canary artifacts,
-- including the encryption-at-rest settings for artifacts that the canary
-- uploads to Amazon S3.
--
-- 'failureRetentionPeriodInDays', 'createCanary_failureRetentionPeriodInDays' - The number of days to retain data about failed runs of this canary. If
-- you omit this field, the default of 31 days is used. The valid range is
-- 1 to 455 days.
--
-- 'runConfig', 'createCanary_runConfig' - A structure that contains the configuration for individual canary runs,
-- such as timeout value and environment variables.
--
-- The environment variables keys and values are not encrypted. Do not
-- store sensitive information in this field.
--
-- 'successRetentionPeriodInDays', 'createCanary_successRetentionPeriodInDays' - The number of days to retain data about successful runs of this canary.
-- If you omit this field, the default of 31 days is used. The valid range
-- is 1 to 455 days.
--
-- 'tags', 'createCanary_tags' - A list of key-value pairs to associate with the canary. You can
-- associate as many as 50 tags with a canary.
--
-- Tags can help you organize and categorize your resources. You can also
-- use them to scope user permissions, by granting a user permission to
-- access or change only the resources that have certain tag values.
--
-- 'vpcConfig', 'createCanary_vpcConfig' - If this canary is to test an endpoint in a VPC, this structure contains
-- information about the subnet and security groups of the VPC endpoint.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_VPC.html Running a Canary in a VPC>.
--
-- 'name', 'createCanary_name' - The name for this canary. Be sure to give it a descriptive name that
-- distinguishes it from other canaries in your account.
--
-- Do not include secrets or proprietary information in your canary names.
-- The canary name makes up part of the canary ARN, and the ARN is included
-- in outbound calls over the internet. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/servicelens_canaries_security.html Security Considerations for Synthetics Canaries>.
--
-- 'code', 'createCanary_code' - A structure that includes the entry point from which the canary should
-- start running your script. If the script is stored in an S3 bucket, the
-- bucket name, key, and version are also included.
--
-- 'artifactS3Location', 'createCanary_artifactS3Location' - The location in Amazon S3 where Synthetics stores artifacts from the
-- test runs of this canary. Artifacts include the log file, screenshots,
-- and HAR files. The name of the S3 bucket can\'t include a period (.).
--
-- 'executionRoleArn', 'createCanary_executionRoleArn' - The ARN of the IAM role to be used to run the canary. This role must
-- already exist, and must include @lambda.amazonaws.com@ as a principal in
-- the trust policy. The role must also have the following permissions:
--
-- -   @s3:PutObject@
--
-- -   @s3:GetBucketLocation@
--
-- -   @s3:ListAllMyBuckets@
--
-- -   @cloudwatch:PutMetricData@
--
-- -   @logs:CreateLogGroup@
--
-- -   @logs:CreateLogStream@
--
-- -   @logs:PutLogEvents@
--
-- 'schedule', 'createCanary_schedule' - A structure that contains information about how often the canary is to
-- run and when these test runs are to stop.
--
-- 'runtimeVersion', 'createCanary_runtimeVersion' - Specifies the runtime version to use for the canary. For a list of valid
-- runtime versions and more information about runtime versions, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_Library.html Canary Runtime Versions>.
newCreateCanary ::
  -- | 'name'
  Prelude.Text ->
  -- | 'code'
  CanaryCodeInput ->
  -- | 'artifactS3Location'
  Prelude.Text ->
  -- | 'executionRoleArn'
  Prelude.Text ->
  -- | 'schedule'
  CanaryScheduleInput ->
  -- | 'runtimeVersion'
  Prelude.Text ->
  CreateCanary
newCreateCanary :: Text
-> CanaryCodeInput
-> Text
-> Text
-> CanaryScheduleInput
-> Text
-> CreateCanary
newCreateCanary
  Text
pName_
  CanaryCodeInput
pCode_
  Text
pArtifactS3Location_
  Text
pExecutionRoleArn_
  CanaryScheduleInput
pSchedule_
  Text
pRuntimeVersion_ =
    CreateCanary'
      { $sel:artifactConfig:CreateCanary' :: Maybe ArtifactConfigInput
artifactConfig = forall a. Maybe a
Prelude.Nothing,
        $sel:failureRetentionPeriodInDays:CreateCanary' :: Maybe Natural
failureRetentionPeriodInDays = forall a. Maybe a
Prelude.Nothing,
        $sel:runConfig:CreateCanary' :: Maybe CanaryRunConfigInput
runConfig = forall a. Maybe a
Prelude.Nothing,
        $sel:successRetentionPeriodInDays:CreateCanary' :: Maybe Natural
successRetentionPeriodInDays = forall a. Maybe a
Prelude.Nothing,
        $sel:tags:CreateCanary' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
        $sel:vpcConfig:CreateCanary' :: Maybe VpcConfigInput
vpcConfig = forall a. Maybe a
Prelude.Nothing,
        $sel:name:CreateCanary' :: Text
name = Text
pName_,
        $sel:code:CreateCanary' :: CanaryCodeInput
code = CanaryCodeInput
pCode_,
        $sel:artifactS3Location:CreateCanary' :: Text
artifactS3Location = Text
pArtifactS3Location_,
        $sel:executionRoleArn:CreateCanary' :: Text
executionRoleArn = Text
pExecutionRoleArn_,
        $sel:schedule:CreateCanary' :: CanaryScheduleInput
schedule = CanaryScheduleInput
pSchedule_,
        $sel:runtimeVersion:CreateCanary' :: Text
runtimeVersion = Text
pRuntimeVersion_
      }

-- | A structure that contains the configuration for canary artifacts,
-- including the encryption-at-rest settings for artifacts that the canary
-- uploads to Amazon S3.
createCanary_artifactConfig :: Lens.Lens' CreateCanary (Prelude.Maybe ArtifactConfigInput)
createCanary_artifactConfig :: Lens' CreateCanary (Maybe ArtifactConfigInput)
createCanary_artifactConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Maybe ArtifactConfigInput
artifactConfig :: Maybe ArtifactConfigInput
$sel:artifactConfig:CreateCanary' :: CreateCanary -> Maybe ArtifactConfigInput
artifactConfig} -> Maybe ArtifactConfigInput
artifactConfig) (\s :: CreateCanary
s@CreateCanary' {} Maybe ArtifactConfigInput
a -> CreateCanary
s {$sel:artifactConfig:CreateCanary' :: Maybe ArtifactConfigInput
artifactConfig = Maybe ArtifactConfigInput
a} :: CreateCanary)

-- | The number of days to retain data about failed runs of this canary. If
-- you omit this field, the default of 31 days is used. The valid range is
-- 1 to 455 days.
createCanary_failureRetentionPeriodInDays :: Lens.Lens' CreateCanary (Prelude.Maybe Prelude.Natural)
createCanary_failureRetentionPeriodInDays :: Lens' CreateCanary (Maybe Natural)
createCanary_failureRetentionPeriodInDays = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Maybe Natural
failureRetentionPeriodInDays :: Maybe Natural
$sel:failureRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
failureRetentionPeriodInDays} -> Maybe Natural
failureRetentionPeriodInDays) (\s :: CreateCanary
s@CreateCanary' {} Maybe Natural
a -> CreateCanary
s {$sel:failureRetentionPeriodInDays:CreateCanary' :: Maybe Natural
failureRetentionPeriodInDays = Maybe Natural
a} :: CreateCanary)

-- | A structure that contains the configuration for individual canary runs,
-- such as timeout value and environment variables.
--
-- The environment variables keys and values are not encrypted. Do not
-- store sensitive information in this field.
createCanary_runConfig :: Lens.Lens' CreateCanary (Prelude.Maybe CanaryRunConfigInput)
createCanary_runConfig :: Lens' CreateCanary (Maybe CanaryRunConfigInput)
createCanary_runConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Maybe CanaryRunConfigInput
runConfig :: Maybe CanaryRunConfigInput
$sel:runConfig:CreateCanary' :: CreateCanary -> Maybe CanaryRunConfigInput
runConfig} -> Maybe CanaryRunConfigInput
runConfig) (\s :: CreateCanary
s@CreateCanary' {} Maybe CanaryRunConfigInput
a -> CreateCanary
s {$sel:runConfig:CreateCanary' :: Maybe CanaryRunConfigInput
runConfig = Maybe CanaryRunConfigInput
a} :: CreateCanary)

-- | The number of days to retain data about successful runs of this canary.
-- If you omit this field, the default of 31 days is used. The valid range
-- is 1 to 455 days.
createCanary_successRetentionPeriodInDays :: Lens.Lens' CreateCanary (Prelude.Maybe Prelude.Natural)
createCanary_successRetentionPeriodInDays :: Lens' CreateCanary (Maybe Natural)
createCanary_successRetentionPeriodInDays = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Maybe Natural
successRetentionPeriodInDays :: Maybe Natural
$sel:successRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
successRetentionPeriodInDays} -> Maybe Natural
successRetentionPeriodInDays) (\s :: CreateCanary
s@CreateCanary' {} Maybe Natural
a -> CreateCanary
s {$sel:successRetentionPeriodInDays:CreateCanary' :: Maybe Natural
successRetentionPeriodInDays = Maybe Natural
a} :: CreateCanary)

-- | A list of key-value pairs to associate with the canary. You can
-- associate as many as 50 tags with a canary.
--
-- Tags can help you organize and categorize your resources. You can also
-- use them to scope user permissions, by granting a user permission to
-- access or change only the resources that have certain tag values.
createCanary_tags :: Lens.Lens' CreateCanary (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createCanary_tags :: Lens' CreateCanary (Maybe (HashMap Text Text))
createCanary_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateCanary' :: CreateCanary -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateCanary
s@CreateCanary' {} Maybe (HashMap Text Text)
a -> CreateCanary
s {$sel:tags:CreateCanary' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateCanary) 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

-- | If this canary is to test an endpoint in a VPC, this structure contains
-- information about the subnet and security groups of the VPC endpoint.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_VPC.html Running a Canary in a VPC>.
createCanary_vpcConfig :: Lens.Lens' CreateCanary (Prelude.Maybe VpcConfigInput)
createCanary_vpcConfig :: Lens' CreateCanary (Maybe VpcConfigInput)
createCanary_vpcConfig = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Maybe VpcConfigInput
vpcConfig :: Maybe VpcConfigInput
$sel:vpcConfig:CreateCanary' :: CreateCanary -> Maybe VpcConfigInput
vpcConfig} -> Maybe VpcConfigInput
vpcConfig) (\s :: CreateCanary
s@CreateCanary' {} Maybe VpcConfigInput
a -> CreateCanary
s {$sel:vpcConfig:CreateCanary' :: Maybe VpcConfigInput
vpcConfig = Maybe VpcConfigInput
a} :: CreateCanary)

-- | The name for this canary. Be sure to give it a descriptive name that
-- distinguishes it from other canaries in your account.
--
-- Do not include secrets or proprietary information in your canary names.
-- The canary name makes up part of the canary ARN, and the ARN is included
-- in outbound calls over the internet. For more information, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/servicelens_canaries_security.html Security Considerations for Synthetics Canaries>.
createCanary_name :: Lens.Lens' CreateCanary Prelude.Text
createCanary_name :: Lens' CreateCanary Text
createCanary_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Text
name :: Text
$sel:name:CreateCanary' :: CreateCanary -> Text
name} -> Text
name) (\s :: CreateCanary
s@CreateCanary' {} Text
a -> CreateCanary
s {$sel:name:CreateCanary' :: Text
name = Text
a} :: CreateCanary)

-- | A structure that includes the entry point from which the canary should
-- start running your script. If the script is stored in an S3 bucket, the
-- bucket name, key, and version are also included.
createCanary_code :: Lens.Lens' CreateCanary CanaryCodeInput
createCanary_code :: Lens' CreateCanary CanaryCodeInput
createCanary_code = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {CanaryCodeInput
code :: CanaryCodeInput
$sel:code:CreateCanary' :: CreateCanary -> CanaryCodeInput
code} -> CanaryCodeInput
code) (\s :: CreateCanary
s@CreateCanary' {} CanaryCodeInput
a -> CreateCanary
s {$sel:code:CreateCanary' :: CanaryCodeInput
code = CanaryCodeInput
a} :: CreateCanary)

-- | The location in Amazon S3 where Synthetics stores artifacts from the
-- test runs of this canary. Artifacts include the log file, screenshots,
-- and HAR files. The name of the S3 bucket can\'t include a period (.).
createCanary_artifactS3Location :: Lens.Lens' CreateCanary Prelude.Text
createCanary_artifactS3Location :: Lens' CreateCanary Text
createCanary_artifactS3Location = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Text
artifactS3Location :: Text
$sel:artifactS3Location:CreateCanary' :: CreateCanary -> Text
artifactS3Location} -> Text
artifactS3Location) (\s :: CreateCanary
s@CreateCanary' {} Text
a -> CreateCanary
s {$sel:artifactS3Location:CreateCanary' :: Text
artifactS3Location = Text
a} :: CreateCanary)

-- | The ARN of the IAM role to be used to run the canary. This role must
-- already exist, and must include @lambda.amazonaws.com@ as a principal in
-- the trust policy. The role must also have the following permissions:
--
-- -   @s3:PutObject@
--
-- -   @s3:GetBucketLocation@
--
-- -   @s3:ListAllMyBuckets@
--
-- -   @cloudwatch:PutMetricData@
--
-- -   @logs:CreateLogGroup@
--
-- -   @logs:CreateLogStream@
--
-- -   @logs:PutLogEvents@
createCanary_executionRoleArn :: Lens.Lens' CreateCanary Prelude.Text
createCanary_executionRoleArn :: Lens' CreateCanary Text
createCanary_executionRoleArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Text
executionRoleArn :: Text
$sel:executionRoleArn:CreateCanary' :: CreateCanary -> Text
executionRoleArn} -> Text
executionRoleArn) (\s :: CreateCanary
s@CreateCanary' {} Text
a -> CreateCanary
s {$sel:executionRoleArn:CreateCanary' :: Text
executionRoleArn = Text
a} :: CreateCanary)

-- | A structure that contains information about how often the canary is to
-- run and when these test runs are to stop.
createCanary_schedule :: Lens.Lens' CreateCanary CanaryScheduleInput
createCanary_schedule :: Lens' CreateCanary CanaryScheduleInput
createCanary_schedule = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {CanaryScheduleInput
schedule :: CanaryScheduleInput
$sel:schedule:CreateCanary' :: CreateCanary -> CanaryScheduleInput
schedule} -> CanaryScheduleInput
schedule) (\s :: CreateCanary
s@CreateCanary' {} CanaryScheduleInput
a -> CreateCanary
s {$sel:schedule:CreateCanary' :: CanaryScheduleInput
schedule = CanaryScheduleInput
a} :: CreateCanary)

-- | Specifies the runtime version to use for the canary. For a list of valid
-- runtime versions and more information about runtime versions, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries_Library.html Canary Runtime Versions>.
createCanary_runtimeVersion :: Lens.Lens' CreateCanary Prelude.Text
createCanary_runtimeVersion :: Lens' CreateCanary Text
createCanary_runtimeVersion = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanary' {Text
runtimeVersion :: Text
$sel:runtimeVersion:CreateCanary' :: CreateCanary -> Text
runtimeVersion} -> Text
runtimeVersion) (\s :: CreateCanary
s@CreateCanary' {} Text
a -> CreateCanary
s {$sel:runtimeVersion:CreateCanary' :: Text
runtimeVersion = Text
a} :: CreateCanary)

instance Core.AWSRequest CreateCanary where
  type AWSResponse CreateCanary = CreateCanaryResponse
  request :: (Service -> Service) -> CreateCanary -> Request CreateCanary
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 CreateCanary
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateCanary)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Canary -> Int -> CreateCanaryResponse
CreateCanaryResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Canary")
            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 CreateCanary where
  hashWithSalt :: Int -> CreateCanary -> Int
hashWithSalt Int
_salt CreateCanary' {Maybe Natural
Maybe (HashMap Text Text)
Maybe CanaryRunConfigInput
Maybe ArtifactConfigInput
Maybe VpcConfigInput
Text
CanaryCodeInput
CanaryScheduleInput
runtimeVersion :: Text
schedule :: CanaryScheduleInput
executionRoleArn :: Text
artifactS3Location :: Text
code :: CanaryCodeInput
name :: Text
vpcConfig :: Maybe VpcConfigInput
tags :: Maybe (HashMap Text Text)
successRetentionPeriodInDays :: Maybe Natural
runConfig :: Maybe CanaryRunConfigInput
failureRetentionPeriodInDays :: Maybe Natural
artifactConfig :: Maybe ArtifactConfigInput
$sel:runtimeVersion:CreateCanary' :: CreateCanary -> Text
$sel:schedule:CreateCanary' :: CreateCanary -> CanaryScheduleInput
$sel:executionRoleArn:CreateCanary' :: CreateCanary -> Text
$sel:artifactS3Location:CreateCanary' :: CreateCanary -> Text
$sel:code:CreateCanary' :: CreateCanary -> CanaryCodeInput
$sel:name:CreateCanary' :: CreateCanary -> Text
$sel:vpcConfig:CreateCanary' :: CreateCanary -> Maybe VpcConfigInput
$sel:tags:CreateCanary' :: CreateCanary -> Maybe (HashMap Text Text)
$sel:successRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
$sel:runConfig:CreateCanary' :: CreateCanary -> Maybe CanaryRunConfigInput
$sel:failureRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
$sel:artifactConfig:CreateCanary' :: CreateCanary -> Maybe ArtifactConfigInput
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ArtifactConfigInput
artifactConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
failureRetentionPeriodInDays
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CanaryRunConfigInput
runConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
successRetentionPeriodInDays
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe VpcConfigInput
vpcConfig
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CanaryCodeInput
code
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
artifactS3Location
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
executionRoleArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` CanaryScheduleInput
schedule
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
runtimeVersion

instance Prelude.NFData CreateCanary where
  rnf :: CreateCanary -> ()
rnf CreateCanary' {Maybe Natural
Maybe (HashMap Text Text)
Maybe CanaryRunConfigInput
Maybe ArtifactConfigInput
Maybe VpcConfigInput
Text
CanaryCodeInput
CanaryScheduleInput
runtimeVersion :: Text
schedule :: CanaryScheduleInput
executionRoleArn :: Text
artifactS3Location :: Text
code :: CanaryCodeInput
name :: Text
vpcConfig :: Maybe VpcConfigInput
tags :: Maybe (HashMap Text Text)
successRetentionPeriodInDays :: Maybe Natural
runConfig :: Maybe CanaryRunConfigInput
failureRetentionPeriodInDays :: Maybe Natural
artifactConfig :: Maybe ArtifactConfigInput
$sel:runtimeVersion:CreateCanary' :: CreateCanary -> Text
$sel:schedule:CreateCanary' :: CreateCanary -> CanaryScheduleInput
$sel:executionRoleArn:CreateCanary' :: CreateCanary -> Text
$sel:artifactS3Location:CreateCanary' :: CreateCanary -> Text
$sel:code:CreateCanary' :: CreateCanary -> CanaryCodeInput
$sel:name:CreateCanary' :: CreateCanary -> Text
$sel:vpcConfig:CreateCanary' :: CreateCanary -> Maybe VpcConfigInput
$sel:tags:CreateCanary' :: CreateCanary -> Maybe (HashMap Text Text)
$sel:successRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
$sel:runConfig:CreateCanary' :: CreateCanary -> Maybe CanaryRunConfigInput
$sel:failureRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
$sel:artifactConfig:CreateCanary' :: CreateCanary -> Maybe ArtifactConfigInput
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ArtifactConfigInput
artifactConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
failureRetentionPeriodInDays
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CanaryRunConfigInput
runConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
successRetentionPeriodInDays
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe VpcConfigInput
vpcConfig
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CanaryCodeInput
code
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
artifactS3Location
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
executionRoleArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf CanaryScheduleInput
schedule
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
runtimeVersion

instance Data.ToHeaders CreateCanary where
  toHeaders :: CreateCanary -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON CreateCanary where
  toJSON :: CreateCanary -> Value
toJSON CreateCanary' {Maybe Natural
Maybe (HashMap Text Text)
Maybe CanaryRunConfigInput
Maybe ArtifactConfigInput
Maybe VpcConfigInput
Text
CanaryCodeInput
CanaryScheduleInput
runtimeVersion :: Text
schedule :: CanaryScheduleInput
executionRoleArn :: Text
artifactS3Location :: Text
code :: CanaryCodeInput
name :: Text
vpcConfig :: Maybe VpcConfigInput
tags :: Maybe (HashMap Text Text)
successRetentionPeriodInDays :: Maybe Natural
runConfig :: Maybe CanaryRunConfigInput
failureRetentionPeriodInDays :: Maybe Natural
artifactConfig :: Maybe ArtifactConfigInput
$sel:runtimeVersion:CreateCanary' :: CreateCanary -> Text
$sel:schedule:CreateCanary' :: CreateCanary -> CanaryScheduleInput
$sel:executionRoleArn:CreateCanary' :: CreateCanary -> Text
$sel:artifactS3Location:CreateCanary' :: CreateCanary -> Text
$sel:code:CreateCanary' :: CreateCanary -> CanaryCodeInput
$sel:name:CreateCanary' :: CreateCanary -> Text
$sel:vpcConfig:CreateCanary' :: CreateCanary -> Maybe VpcConfigInput
$sel:tags:CreateCanary' :: CreateCanary -> Maybe (HashMap Text Text)
$sel:successRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
$sel:runConfig:CreateCanary' :: CreateCanary -> Maybe CanaryRunConfigInput
$sel:failureRetentionPeriodInDays:CreateCanary' :: CreateCanary -> Maybe Natural
$sel:artifactConfig:CreateCanary' :: CreateCanary -> Maybe ArtifactConfigInput
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ArtifactConfig" 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 ArtifactConfigInput
artifactConfig,
            (Key
"FailureRetentionPeriodInDays" 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
failureRetentionPeriodInDays,
            (Key
"RunConfig" 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 CanaryRunConfigInput
runConfig,
            (Key
"SuccessRetentionPeriodInDays" 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
successRetentionPeriodInDays,
            (Key
"Tags" 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 (HashMap Text Text)
tags,
            (Key
"VpcConfig" 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 VpcConfigInput
vpcConfig,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Code" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= CanaryCodeInput
code),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ArtifactS3Location" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
artifactS3Location),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ExecutionRoleArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
executionRoleArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"Schedule" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= CanaryScheduleInput
schedule),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"RuntimeVersion" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
runtimeVersion)
          ]
      )

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

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

-- | /See:/ 'newCreateCanaryResponse' smart constructor.
data CreateCanaryResponse = CreateCanaryResponse'
  { -- | The full details about the canary you have created.
    CreateCanaryResponse -> Maybe Canary
canary :: Prelude.Maybe Canary,
    -- | The response's http status code.
    CreateCanaryResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateCanaryResponse -> CreateCanaryResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateCanaryResponse -> CreateCanaryResponse -> Bool
$c/= :: CreateCanaryResponse -> CreateCanaryResponse -> Bool
== :: CreateCanaryResponse -> CreateCanaryResponse -> Bool
$c== :: CreateCanaryResponse -> CreateCanaryResponse -> Bool
Prelude.Eq, ReadPrec [CreateCanaryResponse]
ReadPrec CreateCanaryResponse
Int -> ReadS CreateCanaryResponse
ReadS [CreateCanaryResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateCanaryResponse]
$creadListPrec :: ReadPrec [CreateCanaryResponse]
readPrec :: ReadPrec CreateCanaryResponse
$creadPrec :: ReadPrec CreateCanaryResponse
readList :: ReadS [CreateCanaryResponse]
$creadList :: ReadS [CreateCanaryResponse]
readsPrec :: Int -> ReadS CreateCanaryResponse
$creadsPrec :: Int -> ReadS CreateCanaryResponse
Prelude.Read, Int -> CreateCanaryResponse -> ShowS
[CreateCanaryResponse] -> ShowS
CreateCanaryResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateCanaryResponse] -> ShowS
$cshowList :: [CreateCanaryResponse] -> ShowS
show :: CreateCanaryResponse -> String
$cshow :: CreateCanaryResponse -> String
showsPrec :: Int -> CreateCanaryResponse -> ShowS
$cshowsPrec :: Int -> CreateCanaryResponse -> ShowS
Prelude.Show, forall x. Rep CreateCanaryResponse x -> CreateCanaryResponse
forall x. CreateCanaryResponse -> Rep CreateCanaryResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateCanaryResponse x -> CreateCanaryResponse
$cfrom :: forall x. CreateCanaryResponse -> Rep CreateCanaryResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateCanaryResponse' 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:
--
-- 'canary', 'createCanaryResponse_canary' - The full details about the canary you have created.
--
-- 'httpStatus', 'createCanaryResponse_httpStatus' - The response's http status code.
newCreateCanaryResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateCanaryResponse
newCreateCanaryResponse :: Int -> CreateCanaryResponse
newCreateCanaryResponse Int
pHttpStatus_ =
  CreateCanaryResponse'
    { $sel:canary:CreateCanaryResponse' :: Maybe Canary
canary = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateCanaryResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The full details about the canary you have created.
createCanaryResponse_canary :: Lens.Lens' CreateCanaryResponse (Prelude.Maybe Canary)
createCanaryResponse_canary :: Lens' CreateCanaryResponse (Maybe Canary)
createCanaryResponse_canary = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateCanaryResponse' {Maybe Canary
canary :: Maybe Canary
$sel:canary:CreateCanaryResponse' :: CreateCanaryResponse -> Maybe Canary
canary} -> Maybe Canary
canary) (\s :: CreateCanaryResponse
s@CreateCanaryResponse' {} Maybe Canary
a -> CreateCanaryResponse
s {$sel:canary:CreateCanaryResponse' :: Maybe Canary
canary = Maybe Canary
a} :: CreateCanaryResponse)

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

instance Prelude.NFData CreateCanaryResponse where
  rnf :: CreateCanaryResponse -> ()
rnf CreateCanaryResponse' {Int
Maybe Canary
httpStatus :: Int
canary :: Maybe Canary
$sel:httpStatus:CreateCanaryResponse' :: CreateCanaryResponse -> Int
$sel:canary:CreateCanaryResponse' :: CreateCanaryResponse -> Maybe Canary
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Canary
canary
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus