examples_test.go 9.8 KB

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