{-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} -- Module : Network.AWS.IAM.CreateRole -- Copyright : (c) 2013-2014 Brendan Hay -- License : This Source Code Form is subject to the terms of -- the Mozilla Public License, v. 2.0. -- A copy of the MPL can be found in the LICENSE file or -- you can obtain it at http://mozilla.org/MPL/2.0/. -- Maintainer : Brendan Hay -- Stability : experimental -- Portability : non-portable (GHC extensions) -- -- Derived from AWS service descriptions, licensed under Apache 2.0. -- | Creates a new role for your AWS account. For more information about roles, go -- to . For information about limitations on role names and -- the number of roles you can create, go to in the /Using IAM/ guide. -- -- The policy in the following example grants permission to an EC2 instance to -- assume the role. -- -- module Network.AWS.IAM.CreateRole ( -- * Request CreateRole -- ** Request constructor , createRole -- ** Request lenses , crAssumeRolePolicyDocument , crPath , crRoleName -- * Response , CreateRoleResponse -- ** Response constructor , createRoleResponse -- ** Response lenses , crrRole ) where import Network.AWS.Prelude import Network.AWS.Request.Query import Network.AWS.IAM.Types import qualified GHC.Exts data CreateRole = CreateRole { _crAssumeRolePolicyDocument :: Text , _crPath :: Maybe Text , _crRoleName :: Text } deriving (Eq, Ord, Read, Show) -- | 'CreateRole' constructor. -- -- The fields accessible through corresponding lenses are: -- -- * 'crAssumeRolePolicyDocument' @::@ 'Text' -- -- * 'crPath' @::@ 'Maybe' 'Text' -- -- * 'crRoleName' @::@ 'Text' -- createRole :: Text -- ^ 'crRoleName' -> Text -- ^ 'crAssumeRolePolicyDocument' -> CreateRole createRole p1 p2 = CreateRole { _crRoleName = p1 , _crAssumeRolePolicyDocument = p2 , _crPath = Nothing } -- | The policy that grants an entity permission to assume the role. crAssumeRolePolicyDocument :: Lens' CreateRole Text crAssumeRolePolicyDocument = lens _crAssumeRolePolicyDocument (\s a -> s { _crAssumeRolePolicyDocument = a }) -- | The path to the role. For more information about paths, see -- in the /Using IAM/ guide. -- -- This parameter is optional. If it is not included, it defaults to a slash -- (/). crPath :: Lens' CreateRole (Maybe Text) crPath = lens _crPath (\s a -> s { _crPath = a }) -- | The name of the role to create. crRoleName :: Lens' CreateRole Text crRoleName = lens _crRoleName (\s a -> s { _crRoleName = a }) newtype CreateRoleResponse = CreateRoleResponse { _crrRole :: Role } deriving (Eq, Read, Show) -- | 'CreateRoleResponse' constructor. -- -- The fields accessible through corresponding lenses are: -- -- * 'crrRole' @::@ 'Role' -- createRoleResponse :: Role -- ^ 'crrRole' -> CreateRoleResponse createRoleResponse p1 = CreateRoleResponse { _crrRole = p1 } -- | Information about the role. crrRole :: Lens' CreateRoleResponse Role crrRole = lens _crrRole (\s a -> s { _crrRole = a }) instance ToPath CreateRole where toPath = const "/" instance ToQuery CreateRole where toQuery CreateRole{..} = mconcat [ "AssumeRolePolicyDocument" =? _crAssumeRolePolicyDocument , "Path" =? _crPath , "RoleName" =? _crRoleName ] instance ToHeaders CreateRole instance AWSRequest CreateRole where type Sv CreateRole = IAM type Rs CreateRole = CreateRoleResponse request = post "CreateRole" response = xmlResponse instance FromXML CreateRoleResponse where parseXML = withElement "CreateRoleResult" $ \x -> CreateRoleResponse <$> x .@ "Role"