examples_test.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package cloudwatch_test
  3. import (
  4. "bytes"
  5. "fmt"
  6. "time"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/service/cloudwatch"
  9. )
  10. var _ time.Duration
  11. var _ bytes.Buffer
  12. func ExampleCloudWatch_DeleteAlarms() {
  13. svc := cloudwatch.New(nil)
  14. params := &cloudwatch.DeleteAlarmsInput{
  15. AlarmNames: []*string{ // Required
  16. aws.String("AlarmName"), // Required
  17. // More values...
  18. },
  19. }
  20. resp, err := svc.DeleteAlarms(params)
  21. if err != nil {
  22. // Print the error, cast err to awserr.Error to get the Code and
  23. // Message from an error.
  24. fmt.Println(err.Error())
  25. return
  26. }
  27. // Pretty-print the response data.
  28. fmt.Println(resp)
  29. }
  30. func ExampleCloudWatch_DescribeAlarmHistory() {
  31. svc := cloudwatch.New(nil)
  32. params := &cloudwatch.DescribeAlarmHistoryInput{
  33. AlarmName: aws.String("AlarmName"),
  34. EndDate: aws.Time(time.Now()),
  35. HistoryItemType: aws.String("HistoryItemType"),
  36. MaxRecords: aws.Int64(1),
  37. NextToken: aws.String("NextToken"),
  38. StartDate: aws.Time(time.Now()),
  39. }
  40. resp, err := svc.DescribeAlarmHistory(params)
  41. if err != nil {
  42. // Print the error, cast err to awserr.Error to get the Code and
  43. // Message from an error.
  44. fmt.Println(err.Error())
  45. return
  46. }
  47. // Pretty-print the response data.
  48. fmt.Println(resp)
  49. }
  50. func ExampleCloudWatch_DescribeAlarms() {
  51. svc := cloudwatch.New(nil)
  52. params := &cloudwatch.DescribeAlarmsInput{
  53. ActionPrefix: aws.String("ActionPrefix"),
  54. AlarmNamePrefix: aws.String("AlarmNamePrefix"),
  55. AlarmNames: []*string{
  56. aws.String("AlarmName"), // Required
  57. // More values...
  58. },
  59. MaxRecords: aws.Int64(1),
  60. NextToken: aws.String("NextToken"),
  61. StateValue: aws.String("StateValue"),
  62. }
  63. resp, err := svc.DescribeAlarms(params)
  64. if err != nil {
  65. // Print the error, cast err to awserr.Error to get the Code and
  66. // Message from an error.
  67. fmt.Println(err.Error())
  68. return
  69. }
  70. // Pretty-print the response data.
  71. fmt.Println(resp)
  72. }
  73. func ExampleCloudWatch_DescribeAlarmsForMetric() {
  74. svc := cloudwatch.New(nil)
  75. params := &cloudwatch.DescribeAlarmsForMetricInput{
  76. MetricName: aws.String("MetricName"), // Required
  77. Namespace: aws.String("Namespace"), // Required
  78. Dimensions: []*cloudwatch.Dimension{
  79. { // Required
  80. Name: aws.String("DimensionName"), // Required
  81. Value: aws.String("DimensionValue"), // Required
  82. },
  83. // More values...
  84. },
  85. Period: aws.Int64(1),
  86. Statistic: aws.String("Statistic"),
  87. Unit: aws.String("StandardUnit"),
  88. }
  89. resp, err := svc.DescribeAlarmsForMetric(params)
  90. if err != nil {
  91. // Print the error, cast err to awserr.Error to get the Code and
  92. // Message from an error.
  93. fmt.Println(err.Error())
  94. return
  95. }
  96. // Pretty-print the response data.
  97. fmt.Println(resp)
  98. }
  99. func ExampleCloudWatch_DisableAlarmActions() {
  100. svc := cloudwatch.New(nil)
  101. params := &cloudwatch.DisableAlarmActionsInput{
  102. AlarmNames: []*string{ // Required
  103. aws.String("AlarmName"), // Required
  104. // More values...
  105. },
  106. }
  107. resp, err := svc.DisableAlarmActions(params)
  108. if err != nil {
  109. // Print the error, cast err to awserr.Error to get the Code and
  110. // Message from an error.
  111. fmt.Println(err.Error())
  112. return
  113. }
  114. // Pretty-print the response data.
  115. fmt.Println(resp)
  116. }
  117. func ExampleCloudWatch_EnableAlarmActions() {
  118. svc := cloudwatch.New(nil)
  119. params := &cloudwatch.EnableAlarmActionsInput{
  120. AlarmNames: []*string{ // Required
  121. aws.String("AlarmName"), // Required
  122. // More values...
  123. },
  124. }
  125. resp, err := svc.EnableAlarmActions(params)
  126. if err != nil {
  127. // Print the error, cast err to awserr.Error to get the Code and
  128. // Message from an error.
  129. fmt.Println(err.Error())
  130. return
  131. }
  132. // Pretty-print the response data.
  133. fmt.Println(resp)
  134. }
  135. func ExampleCloudWatch_GetMetricStatistics() {
  136. svc := cloudwatch.New(nil)
  137. params := &cloudwatch.GetMetricStatisticsInput{
  138. EndTime: aws.Time(time.Now()), // Required
  139. MetricName: aws.String("MetricName"), // Required
  140. Namespace: aws.String("Namespace"), // Required
  141. Period: aws.Int64(1), // Required
  142. StartTime: aws.Time(time.Now()), // Required
  143. Statistics: []*string{ // Required
  144. aws.String("Statistic"), // Required
  145. // More values...
  146. },
  147. Dimensions: []*cloudwatch.Dimension{
  148. { // Required
  149. Name: aws.String("DimensionName"), // Required
  150. Value: aws.String("DimensionValue"), // Required
  151. },
  152. // More values...
  153. },
  154. Unit: aws.String("StandardUnit"),
  155. }
  156. resp, err := svc.GetMetricStatistics(params)
  157. if err != nil {
  158. // Print the error, cast err to awserr.Error to get the Code and
  159. // Message from an error.
  160. fmt.Println(err.Error())
  161. return
  162. }
  163. // Pretty-print the response data.
  164. fmt.Println(resp)
  165. }
  166. func ExampleCloudWatch_ListMetrics() {
  167. svc := cloudwatch.New(nil)
  168. params := &cloudwatch.ListMetricsInput{
  169. Dimensions: []*cloudwatch.DimensionFilter{
  170. { // Required
  171. Name: aws.String("DimensionName"), // Required
  172. Value: aws.String("DimensionValue"),
  173. },
  174. // More values...
  175. },
  176. MetricName: aws.String("MetricName"),
  177. Namespace: aws.String("Namespace"),
  178. NextToken: aws.String("NextToken"),
  179. }
  180. resp, err := svc.ListMetrics(params)
  181. if err != nil {
  182. // Print the error, cast err to awserr.Error to get the Code and
  183. // Message from an error.
  184. fmt.Println(err.Error())
  185. return
  186. }
  187. // Pretty-print the response data.
  188. fmt.Println(resp)
  189. }
  190. func ExampleCloudWatch_PutMetricAlarm() {
  191. svc := cloudwatch.New(nil)
  192. params := &cloudwatch.PutMetricAlarmInput{
  193. AlarmName: aws.String("AlarmName"), // Required
  194. ComparisonOperator: aws.String("ComparisonOperator"), // Required
  195. EvaluationPeriods: aws.Int64(1), // Required
  196. MetricName: aws.String("MetricName"), // Required
  197. Namespace: aws.String("Namespace"), // Required
  198. Period: aws.Int64(1), // Required
  199. Statistic: aws.String("Statistic"), // Required
  200. Threshold: aws.Float64(1.0), // Required
  201. ActionsEnabled: aws.Bool(true),
  202. AlarmActions: []*string{
  203. aws.String("ResourceName"), // Required
  204. // More values...
  205. },
  206. AlarmDescription: aws.String("AlarmDescription"),
  207. Dimensions: []*cloudwatch.Dimension{
  208. { // Required
  209. Name: aws.String("DimensionName"), // Required
  210. Value: aws.String("DimensionValue"), // Required
  211. },
  212. // More values...
  213. },
  214. InsufficientDataActions: []*string{
  215. aws.String("ResourceName"), // Required
  216. // More values...
  217. },
  218. OKActions: []*string{
  219. aws.String("ResourceName"), // Required
  220. // More values...
  221. },
  222. Unit: aws.String("StandardUnit"),
  223. }
  224. resp, err := svc.PutMetricAlarm(params)
  225. if err != nil {
  226. // Print the error, cast err to awserr.Error to get the Code and
  227. // Message from an error.
  228. fmt.Println(err.Error())
  229. return
  230. }
  231. // Pretty-print the response data.
  232. fmt.Println(resp)
  233. }
  234. func ExampleCloudWatch_PutMetricData() {
  235. svc := cloudwatch.New(nil)
  236. params := &cloudwatch.PutMetricDataInput{
  237. MetricData: []*cloudwatch.MetricDatum{ // Required
  238. { // Required
  239. MetricName: aws.String("MetricName"), // Required
  240. Dimensions: []*cloudwatch.Dimension{
  241. { // Required
  242. Name: aws.String("DimensionName"), // Required
  243. Value: aws.String("DimensionValue"), // Required
  244. },
  245. // More values...
  246. },
  247. StatisticValues: &cloudwatch.StatisticSet{
  248. Maximum: aws.Float64(1.0), // Required
  249. Minimum: aws.Float64(1.0), // Required
  250. SampleCount: aws.Float64(1.0), // Required
  251. Sum: aws.Float64(1.0), // Required
  252. },
  253. Timestamp: aws.Time(time.Now()),
  254. Unit: aws.String("StandardUnit"),
  255. Value: aws.Float64(1.0),
  256. },
  257. // More values...
  258. },
  259. Namespace: aws.String("Namespace"), // Required
  260. }
  261. resp, err := svc.PutMetricData(params)
  262. if err != nil {
  263. // Print the error, cast err to awserr.Error to get the Code and
  264. // Message from an error.
  265. fmt.Println(err.Error())
  266. return
  267. }
  268. // Pretty-print the response data.
  269. fmt.Println(resp)
  270. }
  271. func ExampleCloudWatch_SetAlarmState() {
  272. svc := cloudwatch.New(nil)
  273. params := &cloudwatch.SetAlarmStateInput{
  274. AlarmName: aws.String("AlarmName"), // Required
  275. StateReason: aws.String("StateReason"), // Required
  276. StateValue: aws.String("StateValue"), // Required
  277. StateReasonData: aws.String("StateReasonData"),
  278. }
  279. resp, err := svc.SetAlarmState(params)
  280. if err != nil {
  281. // Print the error, cast err to awserr.Error to get the Code and
  282. // Message from an error.
  283. fmt.Println(err.Error())
  284. return
  285. }
  286. // Pretty-print the response data.
  287. fmt.Println(resp)
  288. }