When I am trying to create the cloudwatch alarms for multiple instances via powershell wth of aws cloud cli (below)
$instanceNames = "i-000000123456789", "i-000000123456777";
foreach ($instanceName in $instanceNames) {
aws cloudwatch put-metric-alarm --alarm-name 'Major Alert > Memory Usage exceeds 90%' --alarm-description 'Major Alert > Memory Usage exceeds 90%' --actions-enabled --alarm-actions 'arn:aws:sns:us-east-1:123456789:Test_Topic' 'arn:aws:sns:us-east-1:123456777:Test_Topic' --metric-name 'Memory % Committed Bytes In Use' --namespace 'CWAgent' --statistic 'Average' --dimensions '[{"Name":"InstanceId","Value":"'$instanceName'"}]' --period 300 --evaluation-periods 1 --datapoints-to-alarm 1 --threshold 90 --comparison-operator 'GreaterThanThreshold' --treat-missing-data 'missing'
}
I am getting the below error message:
Error formatting a string: Input string was not in a correct format.. At line:4 char:1
- aws cloudwatch put-metric-alarm --alarm-name 'Major Alert > Memory Us ...
-
+ CategoryInfo : InvalidOperation: ({0}"}]:String) [], RuntimeException + FullyQualifiedErrorId : FormatError
Error formatting a string: Input string was not in a correct format.. At line:4 char:1
- aws cloudwatch put-metric-alarm --alarm-name 'Major Alert > Memory Us ...
-
+ CategoryInfo : InvalidOperation: ({0}"}]:String) [], RuntimeException + FullyQualifiedErrorId : FormatError
Even when I am simply running the cloudwatch cli command for creating an alarm - I getting the same error for parsing the json syntax "Value":"'+$instanceName+'"
Any inputs on this will be highly appreciated !!
Last part parsing error:
Sir, looking for your last assistance:
this is the verbatim string '[{"Name":"instance","Value":"C:"},{"Name":"InstanceId","Value":"i-0123abcxyz"},{"Name":"objectname","Value":"LogicalDisk"}]' and I have parsed it with the below one theway you showed "[{"\`Name\`":"\`instance\`","\`Value\`":"\`C:\`"},{\`"Name\`":\`"InstanceId\`",\`"Value\`":\`"'$instanceName'\`"},{"\`Name\`":"\`objectname\`","\`Value\`":"\`LogicalDisk\`"}]" but still I'm getting error.
Am I missing anything else here ? still it is showing incorrect format. any response on this