Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
310727f
Make getMetricStatistics parametrizable
tiphdousset Apr 12, 2021
dd90b85
Add ECS support: implement listClusters
tiphdousset Apr 12, 2021
ace5e4d
Add new Memory metrics
tiphdousset Apr 13, 2021
ebe7bb1
ECS: implement listTasks
tiphdousset Apr 21, 2021
62cfbf1
ECS: implement listContainerInstances
tiphdousset Apr 22, 2021
f7bf1b3
ECS: add second param to listTasks
tiphdousset Apr 22, 2021
e86d375
WIP: add describeClusters
tiphdousset Apr 22, 2021
b9b02da
WIP
tiphdousset Apr 22, 2021
0dfb95a
WIP: add describeContainerInstances
tiphdousset Apr 22, 2021
ed53ad2
WIP: EC2 add describeInstanceAttribute
tiphdousset Apr 23, 2021
15d2ada
WIP: local testing
tiphdousset Apr 26, 2021
d71b627
WIP: ECS: implement describeTasks
tiphdousset Apr 26, 2021
fa087b3
WIP: Add pricing
tiphdousset Apr 27, 2021
7f3b777
WIP: local testing
tiphdousset Apr 28, 2021
9da6949
WIP: Pricing version with Maybe
tiphdousset Apr 28, 2021
05230a9
WIP: Pricing version with Either
tiphdousset Apr 28, 2021
b4ce258
Purty
tiphdousset Apr 28, 2021
e178f76
WIP Pricing: add more decodeJson
tiphdousset Apr 29, 2021
00153fe
WIP: refactoring getAllProducts
tiphdousset Apr 29, 2021
c60323b
WIP: add effectiveDate field
tiphdousset May 6, 2021
0cb8218
WIP: fix getAllProducts
tiphdousset May 6, 2021
e060a36
WIP: local testing
tiphdousset May 6, 2021
ece06ef
WIP: add newTypes
tiphdousset May 7, 2021
69b451d
WIP: returning newTypes
tiphdousset May 7, 2021
24b1d2d
WIP: add eq
tiphdousset May 7, 2021
ddcb409
WIP: refactoring
tiphdousset May 12, 2021
4977dcd
WIP rename local test Main temporary
tiphdousset May 12, 2021
8e86dbf
Refactoring
tiphdousset May 20, 2021
cea45d6
Add mapping between Region and Location value for filter
tiphdousset May 20, 2021
d03e6ff
WIP: split EC2 and ECS results from pricing request
tiphdousset May 26, 2021
421172f
WIP: getProducts for ECS & EC2 with Either for the Attributes
tiphdousset May 28, 2021
42ed212
Refactoring getAllProducts to getAllEC2Products
tiphdousset May 28, 2021
8608f38
WIP: add filter for ECS fargate
tiphdousset May 28, 2021
cec4450
WIP: refactoring - create ECS & EC2 folders
tiphdousset May 28, 2021
0602294
WIP: update local test
tiphdousset Jun 4, 2021
4c1139b
WIP: Add data type for EC2InstanceType
tiphdousset Jun 4, 2021
3d392e7
WIP: add toBoxUsage
tiphdousset Jun 4, 2021
1a2f7e6
WIP: add list of Regions
tiphdousset Jun 4, 2021
731b4d2
ServiceCode not needed als parameter
tiphdousset Jun 11, 2021
5650482
WIP: edit Main for local testing
tiphdousset Jun 11, 2021
91b3b09
WIP: temporar loging for debuging
tiphdousset Jun 16, 2021
0bf34d7
WIP: add spy
tiphdousset Jun 16, 2021
fcd637f
Upgrade dependencies
tiphdousset Jun 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
790 changes: 489 additions & 301 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"devDependencies": {
"bower": "^1.8.12",
"pulp": "^15.0.0",
"purescript": "^0.14.0",
"purty": "^6.2.0",
"spago": "^0.15.2"
"purescript": "^0.14.2",
"purty": "^7.0.0",
"spago": "^0.20.3"
},
"dependencies": {
"aws-sdk": "^2.665.0"
Expand Down
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.14.0-20210309/packages.dhall sha256:585332a8a11c6420d7287943f81bc2121746cdd352f2cf3f5ecf65053f2afcd3
https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210613/packages.dhall sha256:64d7b5a1921e8458589add8a1499a1c82168e726a87fc4f958b3f8760cca2efe

let overrides = {=}

Expand Down
19 changes: 18 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
{ name = "purescript-aws-sdk-basic"
, dependencies =
[ "aff-promise"
[ "aff"
, "aff-promise"
, "argonaut"
, "argonaut-codecs"
, "arrays"
, "bifunctors"
, "console"
, "datetime"
, "debug"
, "effect"
, "either"
, "exceptions"
, "foreign"
, "foreign-object"
, "formatters"
, "functions"
, "integers"
, "js-date"
, "justifill"
, "maybe"
, "monad-control"
, "newtype"
, "node-buffer"
, "nullable"
, "numbers"
, "ordered-collections"
, "prelude"
, "record"
, "transformers"
, "tuples"
, "unfoldable"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
Expand Down
102 changes: 72 additions & 30 deletions src/AWS/CloudWatch/Cloudwatch.purs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module AWS.CloudWatch
( CloudWatch
, makeClient
, InternalGetMetricStatisticsOutput
, InternalMetricDatapoint
, getMetricStatistics
, getMetricStatisticsAverage
, getMetricStatisticsMaximum
) where

import Prelude
import AWS.CloudWatch.Types (Dimension, GetMetricStatisticsOutput, MetricDatapointMaximum, MetricSettings, Statistics, MetricDatapointAverage)
import AWS.Core.Client (makeClientHelper)
import AWS.Core.Types (DefaultClientProps, InstanceId)
import AWS.Core.Types (DefaultClientProps)
import AWS.Core.Util (handleError)
import Control.Promise (Promise)
import Control.Promise as Promise
import Data.Argonaut (Json, decodeJson, parseJson)
import Data.Argonaut (Json, parseJson)
import Data.Argonaut.Decode (decodeJson)
import Data.Bifunctor (lmap)
import Data.DateTime (DateTime)
import Data.Either (Either)
Expand Down Expand Up @@ -55,36 +56,77 @@ type InternalGetMetricsStatisticsParams
, "Statistics" :: Array String
}

type InternalMetricDatapoint
= { "Timestamp" :: String
, "Maximum" :: Number
, "Unit" :: String
}
type InternalDimension
= { "Name" :: String, "Value" :: String }

type InternalGetMetricStatisticsOutput
= { "ResponseMetadata" :: { "RequestId" :: String }
, "Label" :: String
, "Datapoints" :: Array InternalMetricDatapoint
}
toInternalDimension :: Dimension -> InternalDimension
toInternalDimension dimension =
{ "Name": show dimension.name
, "Value": unwrap dimension.value
}

toInternalGetMetricStatisticsParams ::
forall a.
{ start :: DateTime, end :: DateTime | a } ->
Statistics ->
MetricSettings ->
InternalGetMetricsStatisticsParams
toInternalGetMetricStatisticsParams range statistics ms =
{ "Namespace": nameSpace
, "MetricName": metricName
, "Dimensions": dimensions
, "Statistics": stat
, "StartTime": start
, "EndTime": end
, "Period": 86400 -- 1Day
}
where
nameSpace = show ms.nameSpace

metricName = show ms.metricName

dimensions = ms.dimensions <#> toInternalDimension

foreign import data GetMetricStatisticsResponse :: Type
stat = statistics <#> show

start = fromDateTime range.start

end = fromDateTime range.end

foreign import getMetricStatisticsImpl :: Fn2 CloudWatch InternalGetMetricsStatisticsParams (Effect (Promise String))

getMetricStatistics :: forall a. CloudWatch -> { start :: DateTime, end :: DateTime | a } -> InstanceId -> Aff (Either String InternalGetMetricStatisticsOutput)
getMetricStatistics cw range instanceId = liftEffect curried >>= Promise.toAff <#> parse
curried ::
forall a.
CloudWatch ->
{ start :: DateTime, end :: DateTime | a } ->
Statistics ->
MetricSettings ->
Effect (Promise String)
curried cw range statistics ms = runFn2 getMetricStatisticsImpl cw params
where
params :: InternalGetMetricsStatisticsParams
params = toInternalGetMetricStatisticsParams range statistics ms

getMetricStatisticsMaximum ::
forall a.
CloudWatch ->
{ start :: DateTime, end :: DateTime | a } ->
Statistics ->
MetricSettings ->
Aff (Either String (GetMetricStatisticsOutput MetricDatapointMaximum))
getMetricStatisticsMaximum cw range statistics ms = liftEffect (curried cw range statistics ms) >>= Promise.toAff <#> parse
where
parse :: String -> Either String InternalGetMetricStatisticsOutput
parse :: String -> Either String (GetMetricStatisticsOutput MetricDatapointMaximum)
parse = (parseJson >=> decodeJson) >>> lmap handleError

curried :: Effect (Promise String)
curried =
runFn2 getMetricStatisticsImpl cw
{ "Namespace": "AWS/EC2"
, "MetricName": "CPUUtilization"
, "Dimensions": [ { "Name": "InstanceId", "Value": unwrap instanceId } ]
, "Statistics": [ "Maximum" ]
, "StartTime": fromDateTime range.start
, "EndTime": fromDateTime range.end
, "Period": 86400
}
getMetricStatisticsAverage ::
forall a.
CloudWatch ->
{ start :: DateTime, end :: DateTime | a } ->
Statistics ->
MetricSettings ->
Aff (Either String (GetMetricStatisticsOutput MetricDatapointAverage))
getMetricStatisticsAverage cw range statistics ms = liftEffect (curried cw range statistics ms) >>= Promise.toAff <#> parse
where
parse :: String -> Either String (GetMetricStatisticsOutput MetricDatapointAverage)
parse = (parseJson >=> decodeJson) >>> lmap handleError
80 changes: 80 additions & 0 deletions src/AWS/CloudWatch/Types.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module AWS.CloudWatch.Types where

import Data.Newtype (class Newtype)
import Prelude (class Show)

data Statistic
= Minimum
| Maximum
| Average
| SampleCount
| Sum

instance showStatistic :: Show Statistic where
show Minimum = "Minimum"
show Maximum = "Maximum"
show Average = "Average"
show SampleCount = "SampleCount"
show Sum = "Sum"

type Statistics
= Array Statistic

newtype DimensionValue
= DimensionValue String

derive instance ntDimensionValue :: Newtype DimensionValue _

derive newtype instance showDimensionValue :: Show DimensionValue

data NameSpace
= EC2
| ECS

instance showNameSpace :: Show NameSpace where
show EC2 = "AWS/EC2"
show ECS = "AWS/ECS"

data DimensionName
= EC2InstanceId
| ClusterName

instance showDimensionName :: Show DimensionName where
show EC2InstanceId = "InstanceId"
show ClusterName = "ClusterName"

data MetricName
= CPUUtilization
| CPUReservation
| MemoryUtilization
| MemoryReservation

instance showMetricName :: Show MetricName where
show CPUUtilization = "CPUUtilization"
show CPUReservation = "CPUReservation"
show MemoryUtilization = "MemoryUtilization"
show MemoryReservation = "MemoryReservation"

type Dimension
= { name :: DimensionName, value :: DimensionValue }

type MetricSettings
= { nameSpace :: NameSpace
, metricName :: MetricName
, dimensions :: Array Dimension
}

type Raw
= ( "Timestamp" :: String, "Unit" :: String )

type MetricDatapointAverage
= { "Average" :: Number | Raw }

type MetricDatapointMaximum
= { "Maximum" :: Number | Raw }

type GetMetricStatisticsOutput a
= { "ResponseMetadata" :: { "RequestId" :: String }
, "Label" :: String
, "Datapoints" :: Array a
}
3 changes: 2 additions & 1 deletion src/AWS/Core/Client.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import Justifill.Justifiable (class JustifiableFields)
import Prelude ((>>>))
import Prim.Row (class Nub, class Union)
import Prim.RowList (class RowToList)
import Debug (spy)

makeClientHelper ::
forall additionalProps client.
EncodeJson (BasicClientProps additionalProps) =>
(Json -> Effect client) -> BasicClientProps additionalProps -> Effect client
makeClientHelper newClient = encodeJson >>> newClient
makeClientHelper newClient = spy "makeClientHelper: " >>> encodeJson >>> newClient

makeDefaultClient ::
forall additionalProps output input to toRL inputRL.
Expand Down
4 changes: 3 additions & 1 deletion src/AWS/Core/Credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

var AWS = require('aws-sdk')

exports.newSharedIniFileCredentials = (params) => () => new AWS.SharedIniFileCredentials(params)
exports.newSharedIniFileCredentials = (params) => () => {
console.log("Params SharedIniFileCredentials: ", params);
return new AWS.SharedIniFileCredentials(params);}
Loading