Skip to content

Instantly share code, notes, and snippets.

@rcook
Last active March 30, 2020 05:47
Show Gist options
  • Save rcook/d0b144694361c41f4d450cd79f0bf82e to your computer and use it in GitHub Desktop.
Save rcook/d0b144694361c41f4d450cd79f0bf82e to your computer and use it in GitHub Desktop.
AWS via Haskell: SSM
executable ssm-app
default-language: Haskell2010
hs-source-dirs: ssm
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N -W -Wall -fwarn-incomplete-patterns -fwarn-unused-imports
build-depends: amazonka-ssm
, aws-via-haskell
, base >= 4.7 && < 5
, directory
, filepath
, text
other-modules: SSMImports
The MIT License (MIT)
Copyright (c) 2018 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{-|
Module : Main
Description : SSM (Simple Systems Manager) demo
Copyright : (C) Richard Cook, 2018
License : MIT
Maintainer : [email protected]
Stability : experimental
Portability : portable
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Main (main) where
import AWSViaHaskell
import Control.Monad (void)
import qualified Data.List.NonEmpty as NonEmpty (fromList)
import Data.Maybe (fromJust)
import Data.Monoid ((<>))
import Data.Text (Text)
import qualified Data.Text.IO as Text (putStrLn)
import SSMImports
import System.Directory (getHomeDirectory)
import System.FilePath ((</>))
wrapAWSService 'ssm "SSMService" "SSMSession"
newtype ParameterName = ParameterName Text
newtype ParameterValue = ParameterValue Text
doGetParameter :: ParameterName -> SSMSession -> IO (Text, Integer)
doGetParameter (ParameterName pn) = withAWS $ do
result <- send $ getParameters (NonEmpty.fromList [pn])
let param = head $ result ^. grsParameters
return $ (fromJust (param ^. pValue), fromJust (param ^. pVersion))
doPutParameter :: ParameterName -> ParameterValue -> SSMSession -> IO ()
doPutParameter (ParameterName pn) (ParameterValue pv) = withAWS $
void (send $ putParameter pn pv String & ppOverwrite .~ Just True)
main :: IO ()
main = do
homeDir <- getHomeDirectory
let conf = awsConfig (AWSRegion Ohio)
& awscCredentials .~ (FromFile "aws-via-haskell" $ homeDir </> ".aws" </> "credentials")
ssmSession <- connect conf ssmService
putStrLn "doPutParameter"
doPutParameter (ParameterName "/AAA/BBB") (ParameterValue "CCC") ssmSession
putStrLn "doGetParameter"
(value, version) <- doGetParameter (ParameterName "/AAA/BBB") ssmSession
Text.putStrLn $ "Value: " <> value
putStrLn $ "Version: " ++ show version
putStrLn "Done"
{-|
Module : Main
Description : Imports module for SSM demo
Copyright : (C) Richard Cook, 2018
License : MIT
Maintainer : [email protected]
Stability : experimental
Portability : portable
-}
module SSMImports
( ParameterType(..)
, getParameters
, grsParameters
, pValue
, pVersion
, ppOverwrite
, putParameter
, ssm
) where
import Network.AWS.SSM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment