examples_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. // THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
  2. package cloudwatchlogs_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/cloudwatchlogs"
  9. )
  10. var _ time.Duration
  11. var _ bytes.Buffer
  12. func ExampleCloudWatchLogs_CreateLogGroup() {
  13. svc := cloudwatchlogs.New(nil)
  14. params := &cloudwatchlogs.CreateLogGroupInput{
  15. LogGroupName: aws.String("LogGroupName"), // Required
  16. }
  17. resp, err := svc.CreateLogGroup(params)
  18. if err != nil {
  19. // Print the error, cast err to awserr.Error to get the Code and
  20. // Message from an error.
  21. fmt.Println(err.Error())
  22. return
  23. }
  24. // Pretty-print the response data.
  25. fmt.Println(resp)
  26. }
  27. func ExampleCloudWatchLogs_CreateLogStream() {
  28. svc := cloudwatchlogs.New(nil)
  29. params := &cloudwatchlogs.CreateLogStreamInput{
  30. LogGroupName: aws.String("LogGroupName"), // Required
  31. LogStreamName: aws.String("LogStreamName"), // Required
  32. }
  33. resp, err := svc.CreateLogStream(params)
  34. if err != nil {
  35. // Print the error, cast err to awserr.Error to get the Code and
  36. // Message from an error.
  37. fmt.Println(err.Error())
  38. return
  39. }
  40. // Pretty-print the response data.
  41. fmt.Println(resp)
  42. }
  43. func ExampleCloudWatchLogs_DeleteDestination() {
  44. svc := cloudwatchlogs.New(nil)
  45. params := &cloudwatchlogs.DeleteDestinationInput{
  46. DestinationName: aws.String("DestinationName"), // Required
  47. }
  48. resp, err := svc.DeleteDestination(params)
  49. if err != nil {
  50. // Print the error, cast err to awserr.Error to get the Code and
  51. // Message from an error.
  52. fmt.Println(err.Error())
  53. return
  54. }
  55. // Pretty-print the response data.
  56. fmt.Println(resp)
  57. }
  58. func ExampleCloudWatchLogs_DeleteLogGroup() {
  59. svc := cloudwatchlogs.New(nil)
  60. params := &cloudwatchlogs.DeleteLogGroupInput{
  61. LogGroupName: aws.String("LogGroupName"), // Required
  62. }
  63. resp, err := svc.DeleteLogGroup(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 ExampleCloudWatchLogs_DeleteLogStream() {
  74. svc := cloudwatchlogs.New(nil)
  75. params := &cloudwatchlogs.DeleteLogStreamInput{
  76. LogGroupName: aws.String("LogGroupName"), // Required
  77. LogStreamName: aws.String("LogStreamName"), // Required
  78. }
  79. resp, err := svc.DeleteLogStream(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 ExampleCloudWatchLogs_DeleteMetricFilter() {
  90. svc := cloudwatchlogs.New(nil)
  91. params := &cloudwatchlogs.DeleteMetricFilterInput{
  92. FilterName: aws.String("FilterName"), // Required
  93. LogGroupName: aws.String("LogGroupName"), // Required
  94. }
  95. resp, err := svc.DeleteMetricFilter(params)
  96. if err != nil {
  97. // Print the error, cast err to awserr.Error to get the Code and
  98. // Message from an error.
  99. fmt.Println(err.Error())
  100. return
  101. }
  102. // Pretty-print the response data.
  103. fmt.Println(resp)
  104. }
  105. func ExampleCloudWatchLogs_DeleteRetentionPolicy() {
  106. svc := cloudwatchlogs.New(nil)
  107. params := &cloudwatchlogs.DeleteRetentionPolicyInput{
  108. LogGroupName: aws.String("LogGroupName"), // Required
  109. }
  110. resp, err := svc.DeleteRetentionPolicy(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 ExampleCloudWatchLogs_DeleteSubscriptionFilter() {
  121. svc := cloudwatchlogs.New(nil)
  122. params := &cloudwatchlogs.DeleteSubscriptionFilterInput{
  123. FilterName: aws.String("FilterName"), // Required
  124. LogGroupName: aws.String("LogGroupName"), // Required
  125. }
  126. resp, err := svc.DeleteSubscriptionFilter(params)
  127. if err != nil {
  128. // Print the error, cast err to awserr.Error to get the Code and
  129. // Message from an error.
  130. fmt.Println(err.Error())
  131. return
  132. }
  133. // Pretty-print the response data.
  134. fmt.Println(resp)
  135. }
  136. func ExampleCloudWatchLogs_DescribeDestinations() {
  137. svc := cloudwatchlogs.New(nil)
  138. params := &cloudwatchlogs.DescribeDestinationsInput{
  139. DestinationNamePrefix: aws.String("DestinationName"),
  140. Limit: aws.Int64(1),
  141. NextToken: aws.String("NextToken"),
  142. }
  143. resp, err := svc.DescribeDestinations(params)
  144. if err != nil {
  145. // Print the error, cast err to awserr.Error to get the Code and
  146. // Message from an error.
  147. fmt.Println(err.Error())
  148. return
  149. }
  150. // Pretty-print the response data.
  151. fmt.Println(resp)
  152. }
  153. func ExampleCloudWatchLogs_DescribeLogGroups() {
  154. svc := cloudwatchlogs.New(nil)
  155. params := &cloudwatchlogs.DescribeLogGroupsInput{
  156. Limit: aws.Int64(1),
  157. LogGroupNamePrefix: aws.String("LogGroupName"),
  158. NextToken: aws.String("NextToken"),
  159. }
  160. resp, err := svc.DescribeLogGroups(params)
  161. if err != nil {
  162. // Print the error, cast err to awserr.Error to get the Code and
  163. // Message from an error.
  164. fmt.Println(err.Error())
  165. return
  166. }
  167. // Pretty-print the response data.
  168. fmt.Println(resp)
  169. }
  170. func ExampleCloudWatchLogs_DescribeLogStreams() {
  171. svc := cloudwatchlogs.New(nil)
  172. params := &cloudwatchlogs.DescribeLogStreamsInput{
  173. LogGroupName: aws.String("LogGroupName"), // Required
  174. Descending: aws.Bool(true),
  175. Limit: aws.Int64(1),
  176. LogStreamNamePrefix: aws.String("LogStreamName"),
  177. NextToken: aws.String("NextToken"),
  178. OrderBy: aws.String("OrderBy"),
  179. }
  180. resp, err := svc.DescribeLogStreams(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 ExampleCloudWatchLogs_DescribeMetricFilters() {
  191. svc := cloudwatchlogs.New(nil)
  192. params := &cloudwatchlogs.DescribeMetricFiltersInput{
  193. LogGroupName: aws.String("LogGroupName"), // Required
  194. FilterNamePrefix: aws.String("FilterName"),
  195. Limit: aws.Int64(1),
  196. NextToken: aws.String("NextToken"),
  197. }
  198. resp, err := svc.DescribeMetricFilters(params)
  199. if err != nil {
  200. // Print the error, cast err to awserr.Error to get the Code and
  201. // Message from an error.
  202. fmt.Println(err.Error())
  203. return
  204. }
  205. // Pretty-print the response data.
  206. fmt.Println(resp)
  207. }
  208. func ExampleCloudWatchLogs_DescribeSubscriptionFilters() {
  209. svc := cloudwatchlogs.New(nil)
  210. params := &cloudwatchlogs.DescribeSubscriptionFiltersInput{
  211. LogGroupName: aws.String("LogGroupName"), // Required
  212. FilterNamePrefix: aws.String("FilterName"),
  213. Limit: aws.Int64(1),
  214. NextToken: aws.String("NextToken"),
  215. }
  216. resp, err := svc.DescribeSubscriptionFilters(params)
  217. if err != nil {
  218. // Print the error, cast err to awserr.Error to get the Code and
  219. // Message from an error.
  220. fmt.Println(err.Error())
  221. return
  222. }
  223. // Pretty-print the response data.
  224. fmt.Println(resp)
  225. }
  226. func ExampleCloudWatchLogs_FilterLogEvents() {
  227. svc := cloudwatchlogs.New(nil)
  228. params := &cloudwatchlogs.FilterLogEventsInput{
  229. LogGroupName: aws.String("LogGroupName"), // Required
  230. EndTime: aws.Int64(1),
  231. FilterPattern: aws.String("FilterPattern"),
  232. Interleaved: aws.Bool(true),
  233. Limit: aws.Int64(1),
  234. LogStreamNames: []*string{
  235. aws.String("LogStreamName"), // Required
  236. // More values...
  237. },
  238. NextToken: aws.String("NextToken"),
  239. StartTime: aws.Int64(1),
  240. }
  241. resp, err := svc.FilterLogEvents(params)
  242. if err != nil {
  243. // Print the error, cast err to awserr.Error to get the Code and
  244. // Message from an error.
  245. fmt.Println(err.Error())
  246. return
  247. }
  248. // Pretty-print the response data.
  249. fmt.Println(resp)
  250. }
  251. func ExampleCloudWatchLogs_GetLogEvents() {
  252. svc := cloudwatchlogs.New(nil)
  253. params := &cloudwatchlogs.GetLogEventsInput{
  254. LogGroupName: aws.String("LogGroupName"), // Required
  255. LogStreamName: aws.String("LogStreamName"), // Required
  256. EndTime: aws.Int64(1),
  257. Limit: aws.Int64(1),
  258. NextToken: aws.String("NextToken"),
  259. StartFromHead: aws.Bool(true),
  260. StartTime: aws.Int64(1),
  261. }
  262. resp, err := svc.GetLogEvents(params)
  263. if err != nil {
  264. // Print the error, cast err to awserr.Error to get the Code and
  265. // Message from an error.
  266. fmt.Println(err.Error())
  267. return
  268. }
  269. // Pretty-print the response data.
  270. fmt.Println(resp)
  271. }
  272. func ExampleCloudWatchLogs_PutDestination() {
  273. svc := cloudwatchlogs.New(nil)
  274. params := &cloudwatchlogs.PutDestinationInput{
  275. DestinationName: aws.String("DestinationName"), // Required
  276. RoleArn: aws.String("RoleArn"), // Required
  277. TargetArn: aws.String("TargetArn"), // Required
  278. }
  279. resp, err := svc.PutDestination(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. }
  289. func ExampleCloudWatchLogs_PutDestinationPolicy() {
  290. svc := cloudwatchlogs.New(nil)
  291. params := &cloudwatchlogs.PutDestinationPolicyInput{
  292. AccessPolicy: aws.String("AccessPolicy"), // Required
  293. DestinationName: aws.String("DestinationName"), // Required
  294. }
  295. resp, err := svc.PutDestinationPolicy(params)
  296. if err != nil {
  297. // Print the error, cast err to awserr.Error to get the Code and
  298. // Message from an error.
  299. fmt.Println(err.Error())
  300. return
  301. }
  302. // Pretty-print the response data.
  303. fmt.Println(resp)
  304. }
  305. func ExampleCloudWatchLogs_PutLogEvents() {
  306. svc := cloudwatchlogs.New(nil)
  307. params := &cloudwatchlogs.PutLogEventsInput{
  308. LogEvents: []*cloudwatchlogs.InputLogEvent{ // Required
  309. { // Required
  310. Message: aws.String("EventMessage"), // Required
  311. Timestamp: aws.Int64(1), // Required
  312. },
  313. // More values...
  314. },
  315. LogGroupName: aws.String("LogGroupName"), // Required
  316. LogStreamName: aws.String("LogStreamName"), // Required
  317. SequenceToken: aws.String("SequenceToken"),
  318. }
  319. resp, err := svc.PutLogEvents(params)
  320. if err != nil {
  321. // Print the error, cast err to awserr.Error to get the Code and
  322. // Message from an error.
  323. fmt.Println(err.Error())
  324. return
  325. }
  326. // Pretty-print the response data.
  327. fmt.Println(resp)
  328. }
  329. func ExampleCloudWatchLogs_PutMetricFilter() {
  330. svc := cloudwatchlogs.New(nil)
  331. params := &cloudwatchlogs.PutMetricFilterInput{
  332. FilterName: aws.String("FilterName"), // Required
  333. FilterPattern: aws.String("FilterPattern"), // Required
  334. LogGroupName: aws.String("LogGroupName"), // Required
  335. MetricTransformations: []*cloudwatchlogs.MetricTransformation{ // Required
  336. { // Required
  337. MetricName: aws.String("MetricName"), // Required
  338. MetricNamespace: aws.String("MetricNamespace"), // Required
  339. MetricValue: aws.String("MetricValue"), // Required
  340. },
  341. // More values...
  342. },
  343. }
  344. resp, err := svc.PutMetricFilter(params)
  345. if err != nil {
  346. // Print the error, cast err to awserr.Error to get the Code and
  347. // Message from an error.
  348. fmt.Println(err.Error())
  349. return
  350. }
  351. // Pretty-print the response data.
  352. fmt.Println(resp)
  353. }
  354. func ExampleCloudWatchLogs_PutRetentionPolicy() {
  355. svc := cloudwatchlogs.New(nil)
  356. params := &cloudwatchlogs.PutRetentionPolicyInput{
  357. LogGroupName: aws.String("LogGroupName"), // Required
  358. RetentionInDays: aws.Int64(1), // Required
  359. }
  360. resp, err := svc.PutRetentionPolicy(params)
  361. if err != nil {
  362. // Print the error, cast err to awserr.Error to get the Code and
  363. // Message from an error.
  364. fmt.Println(err.Error())
  365. return
  366. }
  367. // Pretty-print the response data.
  368. fmt.Println(resp)
  369. }
  370. func ExampleCloudWatchLogs_PutSubscriptionFilter() {
  371. svc := cloudwatchlogs.New(nil)
  372. params := &cloudwatchlogs.PutSubscriptionFilterInput{
  373. DestinationArn: aws.String("DestinationArn"), // Required
  374. FilterName: aws.String("FilterName"), // Required
  375. FilterPattern: aws.String("FilterPattern"), // Required
  376. LogGroupName: aws.String("LogGroupName"), // Required
  377. RoleArn: aws.String("RoleArn"),
  378. }
  379. resp, err := svc.PutSubscriptionFilter(params)
  380. if err != nil {
  381. // Print the error, cast err to awserr.Error to get the Code and
  382. // Message from an error.
  383. fmt.Println(err.Error())
  384. return
  385. }
  386. // Pretty-print the response data.
  387. fmt.Println(resp)
  388. }
  389. func ExampleCloudWatchLogs_TestMetricFilter() {
  390. svc := cloudwatchlogs.New(nil)
  391. params := &cloudwatchlogs.TestMetricFilterInput{
  392. FilterPattern: aws.String("FilterPattern"), // Required
  393. LogEventMessages: []*string{ // Required
  394. aws.String("EventMessage"), // Required
  395. // More values...
  396. },
  397. }
  398. resp, err := svc.TestMetricFilter(params)
  399. if err != nil {
  400. // Print the error, cast err to awserr.Error to get the Code and
  401. // Message from an error.
  402. fmt.Println(err.Error())
  403. return
  404. }
  405. // Pretty-print the response data.
  406. fmt.Println(resp)
  407. }